f-21: refacto: move dispatcher to agent specific files
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
0c2dbdb525
commit
19434b1848
9 changed files with 6 additions and 8 deletions
31
internal/dispatcher/agent/dispatcher.go
Normal file
31
internal/dispatcher/agent/dispatcher.go
Normal 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue