-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.go
45 lines (36 loc) · 930 Bytes
/
example.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package worker
import (
"context"
"time"
"github.com/ankorstore/yokai/config"
"github.com/ankorstore/yokai/worker"
)
// ExampleWorker is an example worker.
type ExampleWorker struct {
config *config.Config
}
// NewExampleWorker returns a new [ExampleWorker].
func NewExampleWorker(config *config.Config) *ExampleWorker {
return &ExampleWorker{
config: config,
}
}
// Name returns the [ExampleWorker] name.
func (w *ExampleWorker) Name() string {
return "example-worker"
}
// Run executes the [ExampleWorker].
func (w *ExampleWorker) Run(ctx context.Context) error {
logger := worker.CtxLogger(ctx)
for {
select {
case <-ctx.Done():
logger.Info().Msg("stopping")
return nil
default:
logger.Info().Msg("running")
// The sleep interval can be configured in the application config files.
time.Sleep(time.Duration(w.config.GetFloat64("config.example-worker.interval")) * time.Second)
}
}
}