sync wait --watch

This commit is contained in:
Łukasz Magiera 2020-10-14 18:09:31 +02:00
parent 4ad8d85b13
commit ab4f051b83
4 changed files with 12 additions and 6 deletions

View File

@ -84,6 +84,12 @@ var syncStatusCmd = &cli.Command{
var syncWaitCmd = &cli.Command{ var syncWaitCmd = &cli.Command{
Name: "wait", Name: "wait",
Usage: "Wait for sync to be complete", Usage: "Wait for sync to be complete",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "watch",
Usage: "don't exit after node is synced",
},
},
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
napi, closer, err := GetFullNodeAPI(cctx) napi, closer, err := GetFullNodeAPI(cctx)
if err != nil { if err != nil {
@ -92,7 +98,7 @@ var syncWaitCmd = &cli.Command{
defer closer() defer closer()
ctx := ReqContext(cctx) ctx := ReqContext(cctx)
return SyncWait(ctx, napi) return SyncWait(ctx, napi, cctx.Bool("watch"))
}, },
} }
@ -234,7 +240,7 @@ var syncCheckpointCmd = &cli.Command{
}, },
} }
func SyncWait(ctx context.Context, napi api.FullNode) error { func SyncWait(ctx context.Context, napi api.FullNode, watch bool) error {
tick := time.Second / 4 tick := time.Second / 4
lastLines := 0 lastLines := 0
@ -311,7 +317,7 @@ func SyncWait(ctx context.Context, napi api.FullNode) error {
_ = target // todo: maybe print? (creates a bunch of line wrapping issues with most tipsets) _ = target // todo: maybe print? (creates a bunch of line wrapping issues with most tipsets)
if time.Now().Unix()-int64(head.MinTimestamp()) < int64(build.BlockDelaySecs) { if !watch && time.Now().Unix()-int64(head.MinTimestamp()) < int64(build.BlockDelaySecs) {
fmt.Println("\nDone!") fmt.Println("\nDone!")
return nil return nil
} }

View File

@ -155,7 +155,7 @@ var initCmd = &cli.Command{
log.Info("Checking full node sync status") log.Info("Checking full node sync status")
if !cctx.Bool("genesis-miner") && !cctx.Bool("nosync") { if !cctx.Bool("genesis-miner") && !cctx.Bool("nosync") {
if err := lcli.SyncWait(ctx, api); err != nil { if err := lcli.SyncWait(ctx, api, false); err != nil {
return xerrors.Errorf("sync wait: %w", err) return xerrors.Errorf("sync wait: %w", err)
} }
} }

View File

@ -72,7 +72,7 @@ var initRestoreCmd = &cli.Command{
} }
if !cctx.Bool("nosync") { if !cctx.Bool("nosync") {
if err := lcli.SyncWait(ctx, api); err != nil { if err := lcli.SyncWait(ctx, api, false); err != nil {
return xerrors.Errorf("sync wait: %w", err) return xerrors.Errorf("sync wait: %w", err)
} }
} }

View File

@ -84,7 +84,7 @@ var runCmd = &cli.Command{
log.Info("Checking full node sync status") log.Info("Checking full node sync status")
if !cctx.Bool("nosync") { if !cctx.Bool("nosync") {
if err := lcli.SyncWait(ctx, nodeApi); err != nil { if err := lcli.SyncWait(ctx, nodeApi, false); err != nil {
return xerrors.Errorf("sync wait: %w", err) return xerrors.Errorf("sync wait: %w", err)
} }
} }