f-21: refacto: move dispatcher to agent specific files

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-04-23 22:38:20 +02:00
commit 19434b1848
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
9 changed files with 6 additions and 8 deletions

View file

@ -0,0 +1,31 @@
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)
}
})
}