From 6e176034306026b922c1df4231a1807f36cbe460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20B=C3=BCtow?= Date: Sat, 22 Feb 2020 12:06:09 +0000 Subject: can start commands in background and also cancel those via drun command --- internal/clients/runclient.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'internal/clients') diff --git a/internal/clients/runclient.go b/internal/clients/runclient.go index e3be616..c2f6f62 100644 --- a/internal/clients/runclient.go +++ b/internal/clients/runclient.go @@ -11,10 +11,12 @@ import ( // RunClient is a client to run various commands on the server. type RunClient struct { baseClient + background bool + cancel bool } // NewRunClient returns a new cat client. -func NewRunClient(args Args) (*RunClient, error) { +func NewRunClient(args Args, background, cancel bool) (*RunClient, error) { args.Mode = omode.RunClient c := RunClient{ @@ -23,6 +25,8 @@ func NewRunClient(args Args) (*RunClient, error) { throttleCh: make(chan struct{}, args.ConnectionsPerCPU*runtime.NumCPU()), retry: false, }, + background: background, + cancel: cancel, } c.init(c) @@ -34,12 +38,21 @@ func (c RunClient) makeHandler(server string) handlers.Handler { } func (c RunClient) makeCommands() (commands []string) { - // Send "run COMMAND" to server! if c.Timeout > 0 { - commands = append(commands, fmt.Sprintf("timeout %d %s %s", c.Timeout, c.Mode.String(), c.What)) + commands = append(commands, fmt.Sprintf("timeout %d run%s %s", c.Timeout, c.flags(), c.What)) return } - commands = append(commands, fmt.Sprintf("%s %s", c.Mode.String(), c.What)) + commands = append(commands, fmt.Sprintf("run%s %s", c.flags(), c.What)) return } + +func (c RunClient) flags() string { + if c.background { + return ":background.start" + } + if c.cancel { + return ":background.cancel" + } + return "" +} -- cgit v1.2.3