From 2f82cd6bc9896d220575e45b10ce76b741f4ad9e Mon Sep 17 00:00:00 2001 From: avalkov Date: Fri, 12 Aug 2022 13:22:07 +0300 Subject: [PATCH] Fix scheduler --- cmd/stats-service/main.go | 7 ++++++- internal/tasks/tasks.go | 4 +--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/stats-service/main.go b/cmd/stats-service/main.go index 73768b0..be12c90 100644 --- a/cmd/stats-service/main.go +++ b/cmd/stats-service/main.go @@ -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" @@ -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" ) @@ -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)) diff --git a/internal/tasks/tasks.go b/internal/tasks/tasks.go index 21b4c41..6c31dd7 100644 --- a/internal/tasks/tasks.go +++ b/internal/tasks/tasks.go @@ -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