-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Badaas needs some to run some code periodically, such as the session cache refresh function.
I propose to create an interface
type Routine interface {
// Start the routine
Start() error
// Stop the routines
Stop() error
// Return the name of the routine.
Name() string
}since we use https://github.com/uber-go/fx it should be easy to create a lifecycle hook that manage collected routines.
func StartRoutine(lc fx.Lifecycle, routines []Routine) {
lc.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
for routine := range routines {
err := routine.Start()
if err != nil {
return fmt.Errorf("en error happened while starting routine %q. error=%w", routine.Name(), err)
}
}
return nil
},
OnStop: func(ctx context.Context) error {
for routine := range routines {
err := routine.Stop()
if err != nil {
return fmt.Errorf("en error happened while stopping routine %q. error=%w", routine.Name(), err)
}
}
},
})
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels