2018-08-29 19:17:45 +02:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2020-04-11 15:49:41 +02:00
|
|
|
"context"
|
|
|
|
|
2018-08-29 19:17:45 +02:00
|
|
|
"github.com/pkg/errors"
|
2019-03-22 19:41:12 +01:00
|
|
|
|
2018-10-13 15:07:50 +02:00
|
|
|
"github.com/zrepl/zrepl/cli"
|
2018-08-29 19:17:45 +02:00
|
|
|
"github.com/zrepl/zrepl/config"
|
|
|
|
"github.com/zrepl/zrepl/daemon"
|
|
|
|
)
|
|
|
|
|
2018-10-13 15:07:50 +02:00
|
|
|
var SignalCmd = &cli.Subcommand{
|
2021-01-01 23:32:35 +01:00
|
|
|
Use: "signal [replication|reset|snapshot] JOB",
|
|
|
|
Short: "run a job replication, abort its current invocation, run a snapshot job",
|
2020-04-11 15:49:41 +02:00
|
|
|
Run: func(ctx context.Context, subcommand *cli.Subcommand, args []string) error {
|
2018-10-13 15:07:50 +02:00
|
|
|
return runSignalCmd(subcommand.Config(), args)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func runSignalCmd(config *config.Config, args []string) error {
|
2018-10-12 20:50:30 +02:00
|
|
|
if len(args) != 2 {
|
2021-01-01 23:32:35 +01:00
|
|
|
return errors.Errorf("Expected 2 arguments: [replication|reset|snapshot] JOB")
|
2018-08-29 19:17:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
httpc, err := controlHttpClient(config.Global.Control.SockPath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-10-12 20:50:30 +02:00
|
|
|
err = jsonRequestResponse(httpc, daemon.ControlJobEndpointSignal,
|
2018-08-29 19:17:45 +02:00
|
|
|
struct {
|
|
|
|
Name string
|
2019-03-22 19:41:12 +01:00
|
|
|
Op string
|
2018-08-29 19:17:45 +02:00
|
|
|
}{
|
2018-10-12 20:50:30 +02:00
|
|
|
Name: args[1],
|
2019-03-22 19:41:12 +01:00
|
|
|
Op: args[0],
|
2018-08-29 19:17:45 +02:00
|
|
|
},
|
|
|
|
struct{}{},
|
|
|
|
)
|
|
|
|
return err
|
|
|
|
}
|