mirror of
https://github.com/Dvorinka/SEEN.git
synced 2026-06-04 20:43:03 +00:00
small fix, don't worry about it
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package workers
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type Worker interface {
|
||||
Name() string
|
||||
Start(ctx context.Context) error
|
||||
}
|
||||
|
||||
type Manager struct {
|
||||
workers []Worker
|
||||
log *zap.Logger
|
||||
}
|
||||
|
||||
func NewManager(log *zap.Logger, workers ...Worker) *Manager {
|
||||
return &Manager{workers: workers, log: log}
|
||||
}
|
||||
|
||||
func (m *Manager) Start(ctx context.Context) {
|
||||
for _, worker := range m.workers {
|
||||
worker := worker
|
||||
go func() {
|
||||
m.log.Info("starting worker", zap.String("worker", worker.Name()))
|
||||
if err := worker.Start(ctx); err != nil {
|
||||
m.log.Error("worker stopped", zap.String("worker", worker.Name()), zap.Error(err))
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user