29 lines
725 B
Go
29 lines
725 B
Go
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)
|
|
}
|
|
}
|