zrepl/internal/client/signal.go

43 lines
911 B
Go
Raw Permalink Normal View History

package client
import (
"context"
"github.com/pkg/errors"
2019-03-22 19:41:12 +01:00
"github.com/zrepl/zrepl/internal/cli"
"github.com/zrepl/zrepl/internal/config"
"github.com/zrepl/zrepl/internal/daemon"
)
var SignalCmd = &cli.Subcommand{
Use: "signal [wakeup|reset] JOB",
Short: "wake up a job from wait state or abort its current invocation",
Run: func(ctx context.Context, subcommand *cli.Subcommand, args []string) error {
return runSignalCmd(subcommand.Config(), args)
},
}
func runSignalCmd(config *config.Config, args []string) error {
if len(args) != 2 {
return errors.Errorf("Expected 2 arguments: [wakeup|reset] JOB")
}
httpc, err := controlHttpClient(config.Global.Control.SockPath)
if err != nil {
return err
}
err = jsonRequestResponse(httpc, daemon.ControlJobEndpointSignal,
struct {
Name string
2019-03-22 19:41:12 +01:00
Op string
}{
Name: args[1],
2019-03-22 19:41:12 +01:00
Op: args[0],
},
struct{}{},
)
return err
}