Skip to content

Commit

Permalink
Fix scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
avalkov committed Aug 12, 2022
1 parent b80f78a commit 2f82cd6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 6 additions & 1 deletion cmd/stats-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"net/http"
"time"

cudosapp "github.com/CudoVentures/cudos-node/app"
"github.com/CudoVentures/cudos-stats-v2-service/internal/config"
Expand All @@ -15,6 +16,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/forbole/juno/v2/node/remote"
"github.com/go-co-op/gocron"
"github.com/rs/zerolog/log"
)

Expand Down Expand Up @@ -54,12 +56,15 @@ func main() {
}

log.Info().Msg("Registering tasks")
scheduler := gocron.NewScheduler(time.UTC)

if err := tasks.RegisterTasks(cfg, nodeClient, stakingClient, bankingRestClient, keyValueStorage); err != nil {
if err := tasks.RegisterTasks(scheduler, cfg, nodeClient, stakingClient, bankingRestClient, keyValueStorage); err != nil {
log.Fatal().Err(fmt.Errorf("error while registering tasks: %s", err)).Send()
return
}

scheduler.StartAsync()

log.Info().Msg("Registering http handlers")

http.HandleFunc("/cosmos/mint/v1beta1/annual_provisions", handlers.GetAnnualProvisionsHandler(cfg, keyValueStorage))
Expand Down
4 changes: 1 addition & 3 deletions internal/tasks/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ func ExecuteTasks(cfg config.Config, nodeClient *remote.Node, stakingClient stak
return nil
}

func RegisterTasks(cfg config.Config, nodeClient *remote.Node, stakingClient stakingtypes.QueryClient, bankingClient bankQueryClient, storage keyValueStorage) error {
scheduler := gocron.NewScheduler(time.UTC)

func RegisterTasks(scheduler *gocron.Scheduler, cfg config.Config, nodeClient *remote.Node, stakingClient stakingtypes.QueryClient, bankingClient bankQueryClient, storage keyValueStorage) error {
genesisState, err := createGenesisState(cfg)
if err != nil {
return err
Expand Down

0 comments on commit 2f82cd6

Please sign in to comment.