feat(agent): job runner, compose override executor and swarm executor (#7)
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package updater
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/shcizo/package-updater/internal/protocol"
|
||||
)
|
||||
|
||||
type dispatch struct{ compose, swarm Executor }
|
||||
|
||||
// NewDispatch returns an Executor that picks compose or swarm by job.Kind.
|
||||
// KindContainer and unknown kinds fail.
|
||||
func NewDispatch(compose, swarm Executor) Executor {
|
||||
return dispatch{compose: compose, swarm: swarm}
|
||||
}
|
||||
|
||||
func (d dispatch) Execute(ctx context.Context, job protocol.JobStart, out io.Writer) (string, error) {
|
||||
switch job.Kind {
|
||||
case protocol.KindCompose:
|
||||
return d.compose.Execute(ctx, job, out)
|
||||
case protocol.KindSwarm:
|
||||
return d.swarm.Execute(ctx, job, out)
|
||||
default:
|
||||
return "", fmt.Errorf("cannot update a service of kind %q", job.Kind)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user