f-21: dispatch: add a prepare step to dispatch
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
19434b1848
commit
1d86c45ba4
7 changed files with 102 additions and 21 deletions
|
|
@ -9,6 +9,7 @@ import (
|
|||
)
|
||||
|
||||
type Command interface {
|
||||
Prepare(db *badger.DB, cfg *configuration.Config) error
|
||||
Execute(db *badger.DB, cfg *configuration.Config) error
|
||||
}
|
||||
|
||||
|
|
@ -22,6 +23,10 @@ func New(queue *worker.Queue, db *badger.DB, cfg *configuration.Config) *Dispatc
|
|||
return &Dispatcher{queue: queue, db: db, cfg: cfg}
|
||||
}
|
||||
|
||||
func (d *Dispatcher) Prepare(cmd Command) error {
|
||||
return cmd.Prepare(d.db, d.cfg)
|
||||
}
|
||||
|
||||
func (d *Dispatcher) Dispatch(cmd Command) {
|
||||
d.queue.Submit(func() {
|
||||
if err := cmd.Execute(d.db, d.cfg); err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue