Skip to content

Commit

Permalink
chore: moved controller to a separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Jan 7, 2025
1 parent d3cbda7 commit 64be568
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
5 changes: 3 additions & 2 deletions pkg/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pkg

import (
"context"
controllerPkg "main/pkg/controller"
fetchersPkg "main/pkg/fetchers"
"main/pkg/fs"
generatorsPkg "main/pkg/generators"
Expand Down Expand Up @@ -42,7 +43,7 @@ type App struct {
// based on ValidatorsFetcher and StakingParamsFetcher.
Generators []generatorsPkg.Generator

Controller *fetchersPkg.Controller
Controller *controllerPkg.Controller
}

func NewApp(configPath string, filesystem fs.FS, version string) *App {
Expand Down Expand Up @@ -121,7 +122,7 @@ func NewApp(configPath string, filesystem fs.FS, version string) *App {
generatorsPkg.NewSupplyGenerator(appConfig.Chains),
}

controller := fetchersPkg.NewController(fetchers, logger)
controller := controllerPkg.NewController(fetchers, logger)

server := &http.Server{Addr: appConfig.ListenAddress, Handler: nil}

Expand Down
11 changes: 6 additions & 5 deletions pkg/fetchers/controller.go → pkg/controller/controller.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package fetchers
package controller

import (
"context"
"main/pkg/constants"
fetchersPkg "main/pkg/fetchers"
statePkg "main/pkg/state"
"main/pkg/types"
"sync"
Expand All @@ -23,12 +24,12 @@ func (s FetchersStatuses) IsAllDone(fetcherNames []constants.FetcherName) bool {
}

type Controller struct {
Fetchers Fetchers
Fetchers fetchersPkg.Fetchers
Logger zerolog.Logger
}

func NewController(
fetchers Fetchers,
fetchers fetchersPkg.Fetchers,
logger *zerolog.Logger,
) *Controller {
return &Controller{
Expand All @@ -50,7 +51,7 @@ func (c *Controller) Fetch(ctx context.Context) (
var mutex sync.Mutex
var wg sync.WaitGroup

processFetcher := func(fetcher Fetcher) {
processFetcher := func(fetcher fetchersPkg.Fetcher) {
defer wg.Done()

c.Logger.Trace().Str("name", string(fetcher.Name())).Msg("Processing fetcher...")
Expand Down Expand Up @@ -80,7 +81,7 @@ func (c *Controller) Fetch(ctx context.Context) (
break
}

fetchersToStart := Fetchers{}
fetchersToStart := fetchersPkg.Fetchers{}

for _, fetcher := range c.Fetchers {
if _, ok := fetchersStatus[fetcher.Name()]; ok {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package fetchers
package controller

import (
"context"
"main/assets"
configPkg "main/pkg/config"
fetchersPkg "main/pkg/fetchers"
loggerPkg "main/pkg/logger"
"main/pkg/tendermint"
"main/pkg/tracing"
Expand Down Expand Up @@ -44,20 +45,20 @@ func TestControllerFetcherEnabled(t *testing.T) {
tracing.InitNoopTracer(),
),
}
fetcher1 := NewNodeInfoFetcher(
fetcher1 := fetchersPkg.NewNodeInfoFetcher(
loggerPkg.GetNopLogger(),
chains,
rpcs,
tracing.InitNoopTracer(),
)
fetcher2 := NewRewardsFetcher(
fetcher2 := fetchersPkg.NewRewardsFetcher(
loggerPkg.GetNopLogger(),
chains,
rpcs,
tracing.InitNoopTracer(),
)
logger := loggerPkg.GetNopLogger()
controller := NewController(Fetchers{fetcher1, fetcher2}, logger)
controller := NewController(fetchersPkg.Fetchers{fetcher1, fetcher2}, logger)

data, queryInfos := controller.Fetch(context.Background())
assert.Len(t, queryInfos, 2)
Expand Down

0 comments on commit 64be568

Please sign in to comment.