summaryrefslogtreecommitdiff
path: root/internal/clients
diff options
context:
space:
mode:
authorPaul Bütow <pbuetow@mimecast.com>2020-02-22 12:06:09 +0000
committerPaul Bütow <pbuetow@mimecast.com>2020-02-22 12:06:09 +0000
commit6e176034306026b922c1df4231a1807f36cbe460 (patch)
tree96405450466b12240302d306938c7af9b19f21ba /internal/clients
parent4d2ab8e6dd645d345fa26d8a067ad6dc14fc1fce (diff)
can start commands in background and also cancel those via drun command
Diffstat (limited to 'internal/clients')
-rw-r--r--internal/clients/runclient.go21
1 files changed, 17 insertions, 4 deletions
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 ""
+}