Add flags client request timeout and client retries

This commit is contained in:
Asim 2016-03-29 17:18:39 +01:00
parent 2c2edcad2f
commit 844979be06

View File

@ -38,6 +38,16 @@ var (
DefaultCmd = newCmd()
DefaultFlags = []cli.Flag{
cli.StringFlag{
Name: "client_request_timeout",
EnvVar: "MICRO_CLIENT_REQUEST_TIMEOUT",
Usage: "Sets the client request timeout. e.g 500ms, 5s, 1m. Default: 5s",
},
cli.IntFlag{
Name: "client_retries",
EnvVar: "MICRO_CLIENT_RETRIES",
Usage: "Sets the client retries. Default: 1",
},
cli.StringFlag{
Name: "server_name",
EnvVar: "MICRO_SERVER_NAME",
@ -297,6 +307,19 @@ func (c *cmd) Before(ctx *cli.Context) error {
serverOpts = append(serverOpts, server.Advertise(ctx.String("server_advertise")))
}
// client opts
if r := ctx.Int("client_retries"); r > 0 {
clientOpts = append(clientOpts, client.Retries(r))
}
if t := ctx.String("client_request_timeout"); len(t) > 0 {
d, err := time.ParseDuration(t)
if err != nil {
return fmt.Errorf("failed to parse client_request_timeout: %v", t)
}
clientOpts = append(clientOpts, client.RequestTimeout(d))
}
// We have some command line opts for the server.
// Lets set it up
if len(serverOpts) > 0 {