Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit b2fc6e0

Browse files
authored
Merge pull request #212 from hyperhq/func-sync-call
support --wait parameter for func call command
2 parents 959435e + 778c515 commit b2fc6e0

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

api/client/func.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/docker/engine-api/types/network"
1818
"github.com/docker/engine-api/types/strslice"
1919
"github.com/docker/go-connections/nat"
20-
"github.com/docker/go-units"
20+
units "github.com/docker/go-units"
2121
Cli "github.com/hyperhq/hypercli/cli"
2222
ropts "github.com/hyperhq/hypercli/opts"
2323
flag "github.com/hyperhq/hypercli/pkg/mflag"
@@ -383,6 +383,8 @@ func (cli *DockerCli) CmdFuncInspect(args ...string) error {
383383
// Usage: hyper func call NAME
384384
func (cli *DockerCli) CmdFuncCall(args ...string) error {
385385
cmd := Cli.Subcmd("func call", []string{"NAME"}, "Call a function", false)
386+
wait := cmd.Bool([]string{"-wait"}, false, "Block until the call is completed")
387+
386388
cmd.Require(flag.Exact, 1)
387389
if err := cmd.ParseFlags(args, true); err != nil {
388390
return err
@@ -398,11 +400,24 @@ func (cli *DockerCli) CmdFuncCall(args ...string) error {
398400
}
399401
}
400402

401-
ret, err := cli.client.FuncCall(context.Background(), name, stdin)
403+
body, err := cli.client.FuncCall(context.Background(), name, stdin, *wait)
404+
if err != nil {
405+
return err
406+
}
407+
defer body.Close()
408+
409+
if *wait {
410+
_, err = io.Copy(cli.out, body)
411+
return err
412+
}
413+
414+
var ret types.FuncCallResponse
415+
err = json.NewDecoder(body).Decode(&ret)
402416
if err != nil {
403417
return err
404418
}
405419
fmt.Fprintf(cli.out, "CallId: %s\n", ret.CallId)
420+
406421
return nil
407422
}
408423

@@ -424,9 +439,7 @@ func (cli *DockerCli) CmdFuncGet(args ...string) error {
424439
if err != nil {
425440
return err
426441
}
427-
defer func() {
428-
body.Close()
429-
}()
442+
defer body.Close()
430443

431444
_, err = io.Copy(cli.out, body)
432445
return err

vendor/src/github.com/docker/engine-api/client/func.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,26 +182,24 @@ func (cli *Client) FuncInspectWithCallId(ctx context.Context, id string) (*types
182182
return &fn, err
183183
}
184184

185-
func (cli *Client) FuncCall(ctx context.Context, name string, stdin io.Reader) (*types.FuncCallResponse, error) {
185+
func (cli *Client) FuncCall(ctx context.Context, name string, stdin io.Reader, wait bool) (io.ReadCloser, error) {
186186
fn, _, err := cli.FuncInspectWithRaw(ctx, name)
187187
if err != nil {
188188
return nil, err
189189
}
190-
req, err := newFuncEndpointRequest("POST", path.Join("call", name, fn.UUID), nil, stdin)
191-
if err != nil {
192-
return nil, err
190+
subpath := ""
191+
if wait {
192+
subpath += "/wait"
193193
}
194-
resp, err := funcEndpointRequest(req)
194+
req, err := newFuncEndpointRequest("POST", path.Join("call", name, fn.UUID, subpath), nil, stdin)
195195
if err != nil {
196196
return nil, err
197197
}
198-
defer resp.Body.Close()
199-
var ret types.FuncCallResponse
200-
err = json.NewDecoder(resp.Body).Decode(&ret)
198+
resp, err := funcEndpointRequest(req)
201199
if err != nil {
202200
return nil, err
203201
}
204-
return &ret, nil
202+
return resp.Body, nil
205203
}
206204

207205
func (cli *Client) FuncGet(ctx context.Context, callId string, wait bool) (io.ReadCloser, error) {

vendor/src/github.com/docker/engine-api/client/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ type APIClient interface {
126126
FuncList(ctx context.Context, opts types.FuncListOptions) ([]types.Func, error)
127127
FuncInspect(ctx context.Context, name string) (types.Func, error)
128128
FuncInspectWithRaw(ctx context.Context, name string) (types.Func, []byte, error)
129-
FuncCall(ctx context.Context, name string, stdin io.Reader) (*types.FuncCallResponse, error)
129+
FuncCall(ctx context.Context, name string, stdin io.Reader, wait bool) (io.ReadCloser, error)
130130
FuncGet(ctx context.Context, callId string, wait bool) (io.ReadCloser, error)
131131
FuncLogs(ctx context.Context, name, callId string, follow bool, tail string) (io.ReadCloser, error)
132132
FuncStatus(ctx context.Context, name string) (*types.FuncStatusResponse, error)

0 commit comments

Comments
 (0)