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

feat(cli): add forest-cli wait-api #5259

Merged
merged 8 commits into from
Feb 13, 2025
Merged

feat(cli): add forest-cli wait-api #5259

merged 8 commits into from
Feb 13, 2025

Conversation

hanabi1224
Copy link
Contributor

@hanabi1224 hanabi1224 commented Feb 10, 2025

Summary of changes

This PR ports lotus wait-api to Forest

Changes introduced in this pull request:

  • add forest-cli wait-api command
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()
	},
}

Reference issue to close (if applicable)

Closes #5248

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

@hanabi1224 hanabi1224 marked this pull request as ready for review February 10, 2025 07:29
@hanabi1224 hanabi1224 requested a review from a team as a code owner February 10, 2025 07:29
@hanabi1224 hanabi1224 requested review from lemmih and LesnyRumcajs and removed request for a team February 10, 2025 07:29
echo "Forest RPC endpoint is unavailable - sleeping for 1s"
sleep 1
done
forest_wait_api
Copy link
Contributor Author

@hanabi1224 hanabi1224 Feb 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/cli/subcommands/wait_api_cmd.rs Outdated Show resolved Hide resolved
src/cli/subcommands/wait_api_cmd.rs Outdated Show resolved Hide resolved
src/cli/subcommands/wait_api_cmd.rs Outdated Show resolved Hide resolved

#[derive(Debug, clap::Args)]
pub struct WaitApiCommand {
/// duration to wait till fail
Copy link
Member

@LesnyRumcajs LesnyRumcajs Feb 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make sense to specify the input type (some examples?). Reading the description I am not sure if I should type --timeout 30 or --timeout 30s or --timeout 0.5min without going deeper into the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Member

@LesnyRumcajs LesnyRumcajs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rock-solid

@hanabi1224 hanabi1224 enabled auto-merge February 11, 2025 16:00
@hanabi1224 hanabi1224 added this pull request to the merge queue Feb 13, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 13, 2025
@hanabi1224 hanabi1224 added this pull request to the merge queue Feb 13, 2025
github-merge-queue bot pushed a commit that referenced this pull request Feb 13, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 13, 2025
@hanabi1224 hanabi1224 added this pull request to the merge queue Feb 13, 2025
Merged via the queue into main with commit 4a11a75 Feb 13, 2025
43 checks passed
@hanabi1224 hanabi1224 deleted the hm/wait-api branch February 13, 2025 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

implement forest-cli wait-api that is similar to lotus wait-api
3 participants