Skip to content

Commit fd0e7d3

Browse files
committed
chore!: refactor ServiceFn and pass runner
The service function is renamed and in addition to the context also receives the Runner instance
1 parent 1c727a9 commit fd0e7d3

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

rolling-shutter/chainobserver/observer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (c *ChainObserver) Start(ctx context.Context, runner service.Runner) error
7979
log.Info().Uint64("from-block", fromBlock).Uint64("from-log-index", fromLogIndex).
8080
Msg("starting event syncing")
8181
syncer := eventsyncer.New(c.Client, finalityOffset, eventTypes, fromBlock, fromLogIndex)
82-
handleSyncLoop := func(ctx context.Context) error {
82+
handleSyncLoop := func(ctx context.Context, _ service.Runner) error {
8383
for {
8484
select {
8585
case <-ctx.Done():
@@ -102,5 +102,5 @@ func (c *ChainObserver) Start(ctx context.Context, runner service.Runner) error
102102
}
103103
}
104104
}
105-
return runner.StartService(syncer, service.ServiceFn{Fn: handleSyncLoop})
105+
return runner.StartService(syncer, service.Function{Func: handleSyncLoop})
106106
}

rolling-shutter/keyper/keyper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (kpr *KeyperCore) Start(ctx context.Context, runner service.Runner) error {
166166
func (kpr *KeyperCore) getServices() []service.Service {
167167
services := []service.Service{
168168
kpr.messaging,
169-
service.ServiceFn{Fn: kpr.operateShuttermint},
169+
service.Function{Func: kpr.operateShuttermint},
170170
newEonPubKeyHandler(kpr),
171171
}
172172
keyTrigger := kpr.trigger
@@ -334,7 +334,7 @@ func (kpr *KeyperCore) handleOnChainKeyperSetChanges(
334334

335335
// TODO: we need a better block syncing mechanism!
336336
// Also this is doing too much work sequentially in one routine.
337-
func (kpr *KeyperCore) operateShuttermint(ctx context.Context) error {
337+
func (kpr *KeyperCore) operateShuttermint(ctx context.Context, _ service.Runner) error {
338338
for {
339339
syncBlockNumber, err := retry.FunctionCall(ctx, kpr.blockSyncClient.BlockNumber)
340340
if err != nil {

rolling-shutter/medley/channel/fanin_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ func TestFanIn(t *testing.T) {
3636
end := end
3737
step := numFns
3838
channels = append(channels, ch)
39-
fnService := service.ServiceFn{
40-
Fn: func(ctx context.Context) error {
39+
fnService := service.Function{
40+
Func: func(ctx context.Context, _ service.Runner) error {
4141
putInts(ctx, ch, start, end, step)
4242
return nil
4343
},
@@ -48,8 +48,8 @@ func TestFanIn(t *testing.T) {
4848
services = append(services, fanIn)
4949

5050
result := []int{}
51-
fanConsumer := service.ServiceFn{
52-
Fn: func(ctx context.Context) error {
51+
fanConsumer := service.Function{
52+
Func: func(ctx context.Context, _ service.Runner) error {
5353
for val := range fanIn.C {
5454
result = append(result, val)
5555
}

rolling-shutter/medley/service/service.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ func RunWithSighandler(ctx context.Context, services ...Service) error {
121121
return err
122122
}
123123

124-
type ServiceFn struct {
125-
Fn func(ctx context.Context) error
124+
type Function struct {
125+
Func func(ctx context.Context, group Runner) error
126126
}
127127

128-
func (sf ServiceFn) Start(ctx context.Context, group Runner) error { //nolint:unparam
128+
func (sf Function) Start(ctx context.Context, group Runner) error { //nolint:unparam
129129
group.Go(func() error {
130-
return sf.Fn(ctx)
130+
return sf.Func(ctx, group)
131131
})
132132
return nil
133133
}

0 commit comments

Comments
 (0)