etcdctl: use a context with -total-timeout in simple commands
Like the commit 8ebc933111
, this commit lets simple etcdctl commands
use a context with timeout value passed via -total-timeout.
This commit doesn't change complex commands like watch,
cluster-health, and import because it is not obvious that using the
context in the commands is good or not.
This commit is contained in:
@ -19,7 +19,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/codegangsta/cli"
|
||||
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
|
||||
"github.com/coreos/etcd/client"
|
||||
)
|
||||
|
||||
@ -46,7 +45,9 @@ func mkdirCommandFunc(c *cli.Context, ki client.KeysAPI, prevExist client.PrevEx
|
||||
key := c.Args()[0]
|
||||
ttl := c.Int("ttl")
|
||||
|
||||
_, err := ki.Set(context.TODO(), key, "", &client.SetOptions{TTL: time.Duration(ttl) * time.Second, Dir: true, PrevExist: prevExist})
|
||||
ctx, cancel := contextWithTotalTimeout(c)
|
||||
_, err := ki.Set(ctx, key, "", &client.SetOptions{TTL: time.Duration(ttl) * time.Second, Dir: true, PrevExist: prevExist})
|
||||
cancel()
|
||||
if err != nil {
|
||||
handleError(ExitServerError, err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user