two/internal/dispatcher/agent/dispatcher.go
GnomeZworc 19434b1848
f-21: refacto: move dispatcher to agent specific files
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2026-04-23 22:50:12 +02:00

31 lines
674 B
Go

package dispatcher
import (
"log"
configuration "git.g3e.fr/syonad/two/internal/config/agent"
"git.g3e.fr/syonad/two/pkg/worker"
"github.com/dgraph-io/badger/v4"
)
type Command interface {
Execute(db *badger.DB, cfg *configuration.Config) error
}
type Dispatcher struct {
queue *worker.Queue
db *badger.DB
cfg *configuration.Config
}
func New(queue *worker.Queue, db *badger.DB, cfg *configuration.Config) *Dispatcher {
return &Dispatcher{queue: queue, db: db, cfg: cfg}
}
func (d *Dispatcher) Dispatch(cmd Command) {
d.queue.Submit(func() {
if err := cmd.Execute(d.db, d.cfg); err != nil {
log.Printf("command error (%T): %v", cmd, err)
}
})
}