etcdctl: add per request timeout
This commit is contained in:
@ -47,7 +47,6 @@ func getCommandFunc(c *cli.Context, ki client.KeysAPI) {
|
|||||||
key := c.Args()[0]
|
key := c.Args()[0]
|
||||||
sorted := c.Bool("sort")
|
sorted := c.Bool("sort")
|
||||||
|
|
||||||
// TODO: handle transport timeout
|
|
||||||
resp, err := ki.Get(context.TODO(), key, &client.GetOptions{Sort: sorted})
|
resp, err := ki.Get(context.TODO(), key, &client.GetOptions{Sort: sorted})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(ExitServerError, err)
|
handleError(ExitServerError, err)
|
||||||
|
@ -47,7 +47,6 @@ func lsCommandFunc(c *cli.Context, ki client.KeysAPI) {
|
|||||||
sort := c.Bool("sort")
|
sort := c.Bool("sort")
|
||||||
recursive := c.Bool("recursive")
|
recursive := c.Bool("recursive")
|
||||||
|
|
||||||
// TODO: handle transport timeout
|
|
||||||
resp, err := ki.Get(context.TODO(), key, &client.GetOptions{Sort: sort, Recursive: recursive})
|
resp, err := ki.Get(context.TODO(), key, &client.GetOptions{Sort: sort, Recursive: recursive})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(ExitServerError, err)
|
handleError(ExitServerError, err)
|
||||||
|
@ -51,7 +51,6 @@ func mkCommandFunc(c *cli.Context, ki client.KeysAPI) {
|
|||||||
|
|
||||||
ttl := c.Int("ttl")
|
ttl := c.Int("ttl")
|
||||||
|
|
||||||
// TODO: handle transport timeout
|
|
||||||
resp, err := ki.Set(context.TODO(), key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevExist: client.PrevIgnore})
|
resp, err := ki.Set(context.TODO(), key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevExist: client.PrevIgnore})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(ExitServerError, err)
|
handleError(ExitServerError, err)
|
||||||
|
@ -46,7 +46,6 @@ func mkdirCommandFunc(c *cli.Context, ki client.KeysAPI, prevExist client.PrevEx
|
|||||||
key := c.Args()[0]
|
key := c.Args()[0]
|
||||||
ttl := c.Int("ttl")
|
ttl := c.Int("ttl")
|
||||||
|
|
||||||
// TODO: handle transport timeout
|
|
||||||
_, err := ki.Set(context.TODO(), key, "", &client.SetOptions{TTL: time.Duration(ttl) * time.Second, Dir: true, PrevExist: prevExist})
|
_, err := ki.Set(context.TODO(), key, "", &client.SetOptions{TTL: time.Duration(ttl) * time.Second, Dir: true, PrevExist: prevExist})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(ExitServerError, err)
|
handleError(ExitServerError, err)
|
||||||
|
@ -50,7 +50,6 @@ func rmCommandFunc(c *cli.Context, ki client.KeysAPI) {
|
|||||||
prevValue := c.String("with-value")
|
prevValue := c.String("with-value")
|
||||||
prevIndex := c.Int("with-index")
|
prevIndex := c.Int("with-index")
|
||||||
|
|
||||||
// TODO: handle transport timeout
|
|
||||||
resp, err := ki.Delete(context.TODO(), key, &client.DeleteOptions{PrevIndex: uint64(prevIndex), PrevValue: prevValue, Dir: dir, Recursive: recursive})
|
resp, err := ki.Delete(context.TODO(), key, &client.DeleteOptions{PrevIndex: uint64(prevIndex), PrevValue: prevValue, Dir: dir, Recursive: recursive})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(ExitServerError, err)
|
handleError(ExitServerError, err)
|
||||||
|
@ -40,7 +40,6 @@ func rmdirCommandFunc(c *cli.Context, ki client.KeysAPI) {
|
|||||||
}
|
}
|
||||||
key := c.Args()[0]
|
key := c.Args()[0]
|
||||||
|
|
||||||
// TODO: handle transport timeout
|
|
||||||
resp, err := ki.Delete(context.TODO(), key, &client.DeleteOptions{Dir: true})
|
resp, err := ki.Delete(context.TODO(), key, &client.DeleteOptions{Dir: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(ExitServerError, err)
|
handleError(ExitServerError, err)
|
||||||
|
@ -55,7 +55,6 @@ func setCommandFunc(c *cli.Context, ki client.KeysAPI) {
|
|||||||
prevValue := c.String("swap-with-value")
|
prevValue := c.String("swap-with-value")
|
||||||
prevIndex := c.Int("swap-with-index")
|
prevIndex := c.Int("swap-with-index")
|
||||||
|
|
||||||
// TODO: handle transport timeout
|
|
||||||
resp, err := ki.Set(context.TODO(), key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevIndex: uint64(prevIndex), PrevValue: prevValue})
|
resp, err := ki.Set(context.TODO(), key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevIndex: uint64(prevIndex), PrevValue: prevValue})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(ExitServerError, err)
|
handleError(ExitServerError, err)
|
||||||
|
@ -51,7 +51,6 @@ func updateCommandFunc(c *cli.Context, ki client.KeysAPI) {
|
|||||||
|
|
||||||
ttl := c.Int("ttl")
|
ttl := c.Int("ttl")
|
||||||
|
|
||||||
// TODO: handle transport timeout
|
|
||||||
resp, err := ki.Set(context.TODO(), key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevExist: client.PrevExist})
|
resp, err := ki.Set(context.TODO(), key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevExist: client.PrevExist})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(ExitServerError, err)
|
handleError(ExitServerError, err)
|
||||||
|
@ -51,7 +51,6 @@ func updatedirCommandFunc(c *cli.Context, ki client.KeysAPI) {
|
|||||||
|
|
||||||
ttl := c.Int("ttl")
|
ttl := c.Int("ttl")
|
||||||
|
|
||||||
// TODO: handle transport timeout
|
|
||||||
_, err = ki.Set(context.TODO(), key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, Dir: true, PrevExist: client.PrevExist})
|
_, err = ki.Set(context.TODO(), key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, Dir: true, PrevExist: client.PrevExist})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(ExitServerError, err)
|
handleError(ExitServerError, err)
|
||||||
|
@ -188,8 +188,9 @@ func mustNewClient(c *cli.Context) client.Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cfg := client.Config{
|
cfg := client.Config{
|
||||||
Transport: tr,
|
Transport: tr,
|
||||||
Endpoints: eps,
|
Endpoints: eps,
|
||||||
|
HeaderTimeoutPerRequest: c.GlobalDuration("timeout"),
|
||||||
}
|
}
|
||||||
|
|
||||||
uFlag := c.GlobalString("username")
|
uFlag := c.GlobalString("username")
|
||||||
|
@ -16,6 +16,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/codegangsta/cli"
|
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/codegangsta/cli"
|
||||||
"github.com/coreos/etcd/etcdctl/command"
|
"github.com/coreos/etcd/etcdctl/command"
|
||||||
@ -37,6 +38,7 @@ func main() {
|
|||||||
cli.StringFlag{Name: "key-file", Value: "", Usage: "identify HTTPS client using this SSL key file"},
|
cli.StringFlag{Name: "key-file", Value: "", Usage: "identify HTTPS client using this SSL key file"},
|
||||||
cli.StringFlag{Name: "ca-file", Value: "", Usage: "verify certificates of HTTPS-enabled servers using this CA bundle"},
|
cli.StringFlag{Name: "ca-file", Value: "", Usage: "verify certificates of HTTPS-enabled servers using this CA bundle"},
|
||||||
cli.StringFlag{Name: "username, u", Value: "", Usage: "provide username[:password] and prompt if password is not supplied."},
|
cli.StringFlag{Name: "username, u", Value: "", Usage: "provide username[:password] and prompt if password is not supplied."},
|
||||||
|
cli.DurationFlag{Name: "timeout", Value: time.Second, Usage: "connection timeout per request"},
|
||||||
}
|
}
|
||||||
app.Commands = []cli.Command{
|
app.Commands = []cli.Command{
|
||||||
command.NewBackupCommand(),
|
command.NewBackupCommand(),
|
||||||
|
Reference in New Issue
Block a user