Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add timeout flag to wait-api command #7592

Merged
merged 1 commit into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions cli/wait.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
"context"
"fmt"
"time"

Expand All @@ -10,8 +11,22 @@ import (
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 {
for i := 0; i < 30; i++ {
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)
Expand All @@ -20,15 +35,18 @@ var WaitApiCmd = &cli.Command{
}
defer closer()

ctx := ReqContext(cctx)

_, err = api.Version(ctx)
if err != nil {
return err
}

return nil
}
return fmt.Errorf("timed out waiting for api to come online")

if ctx.Err() == context.DeadlineExceeded {
return fmt.Errorf("timed out waiting for api to come online")
}

return ctx.Err()
},
}
3 changes: 2 additions & 1 deletion documentation/en/cli-lotus-miner.md
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,8 @@ CATEGORY:
DEVELOPER

OPTIONS:
--help, -h show help (default: false)
--timeout value duration to wait till fail (default: 30s)
--help, -h show help (default: false)

```

Expand Down
3 changes: 2 additions & 1 deletion documentation/en/cli-lotus.md
Original file line number Diff line number Diff line change
Expand Up @@ -2450,7 +2450,8 @@ CATEGORY:
DEVELOPER

OPTIONS:
--help, -h show help (default: false)
--timeout value duration to wait till fail (default: 30s)
--help, -h show help (default: false)

```

Expand Down