client exponential backoff
This commit is contained in:
parent
5997dc44d8
commit
82946a1480
@ -3,9 +3,11 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/twitchtv/twirp"
|
"github.com/twitchtv/twirp"
|
||||||
|
|
||||||
@ -36,12 +38,18 @@ func main() {
|
|||||||
for i := 0; ; i++ {
|
for i := 0; ; i++ {
|
||||||
s <- true
|
s <- true
|
||||||
go func(j int) {
|
go func(j int) {
|
||||||
resp, err := c.Hello(ctx, &pb.HelloReq{Subject: strings.Join(os.Args[2:], " ")})
|
sleep := time.Duration(250+rand.Intn(500)) * time.Millisecond
|
||||||
if err != nil {
|
for {
|
||||||
fmt.Fprintf(os.Stderr, "hello: %#v\n", err)
|
resp, err := c.Hello(ctx, &pb.HelloReq{Subject: strings.Join(os.Args[2:], " ")})
|
||||||
os.Exit(1)
|
if err == nil {
|
||||||
|
fmt.Printf("0x%08x: %#v\n", j, resp)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
fmt.Fprintf(os.Stderr, "sleeping %v because: %v\n", sleep, err)
|
||||||
|
time.Sleep(sleep)
|
||||||
|
sleep *= 2
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
fmt.Printf("0x%08x: %#v\n", j, resp)
|
|
||||||
<-s
|
<-s
|
||||||
}(i)
|
}(i)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user