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:
Hitoshi Mitake
2015-09-29 17:20:10 +09:00
parent 6c05a01ec6
commit 33a0df3e33
9 changed files with 27 additions and 18 deletions

View File

@ -20,7 +20,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"
)
@ -51,7 +50,9 @@ func updateCommandFunc(c *cli.Context, ki client.KeysAPI) {
ttl := c.Int("ttl")
resp, err := ki.Set(context.TODO(), key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevExist: client.PrevExist})
ctx, cancel := contextWithTotalTimeout(c)
resp, err := ki.Set(ctx, key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevExist: client.PrevExist})
cancel()
if err != nil {
handleError(ExitServerError, err)
}