forked from filecoin-project/lotus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wait.go
52 lines (44 loc) · 912 Bytes
/
wait.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package cli
import (
"context"
"fmt"
"time"
"github.com/urfave/cli/v2"
)
var WaitApiCmd = &cli.Command{
Name: "wait-api",
Usage: "Wait for lotus api to come online",
Flags: []cli.Flag{
&cli.DurationFlag{
Name: "timeout",
Usage: "duration to wait till fail",
Value: time.Second * 30,
},
},
Action: func(cctx *cli.Context) error {
ctx := ReqContext(cctx)
ctx, cancel := context.WithTimeout(ctx, cctx.Duration("timeout"))
defer cancel()
for {
if ctx.Err() != nil {
break
}
api, closer, err := GetAPI(cctx)
if err != nil {
fmt.Printf("Not online yet... (%s)\n", err)
time.Sleep(time.Second)
continue
}
defer closer()
_, err = api.Version(ctx)
if err != nil {
return err
}
return nil
}
if ctx.Err() == context.DeadlineExceeded {
return fmt.Errorf("timed out waiting for api to come online")
}
return ctx.Err()
},
}