mirror of
https://github.com/makayabou/asg-server.git
synced 2026-05-02 17:43:36 +02:00
38 lines
589 B
Go
38 lines
589 B
Go
package tasks
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.uber.org/fx"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
var Module = fx.Module(
|
|
"tasks",
|
|
fx.Decorate(func(log *zap.Logger) *zap.Logger {
|
|
return log.Named("tasks")
|
|
}),
|
|
fx.Provide(
|
|
NewHashingTask,
|
|
fx.Private,
|
|
),
|
|
fx.Invoke(
|
|
func(lc fx.Lifecycle, task *HashingTask) error {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
lc.Append(fx.Hook{
|
|
OnStart: func(_ context.Context) error {
|
|
go task.Run(ctx)
|
|
return nil
|
|
},
|
|
OnStop: func(_ context.Context) error {
|
|
cancel()
|
|
return nil
|
|
},
|
|
})
|
|
|
|
return nil
|
|
},
|
|
),
|
|
)
|