Skip to content

Commit

Permalink
fix: record first start time in core module (#601)
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudoyu authored Oct 23, 2024
1 parent 3706d1f commit 5d0e688
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,24 +155,16 @@ var command = cobra.Command{
return fmt.Errorf("update current block start: %w", err)
}
}

// set first start time
firstStartTime, err := info.GetFirstStartTime()
if err != nil {
return fmt.Errorf("get first start time: %w", err)
}

if firstStartTime == 0 {
// update first start time to current timestamp in seconds
err = info.UpdateFirstStartTime(time.Now().Unix())
if err != nil {
return fmt.Errorf("update first start time: %w", err)
}
}
}

switch module {
case CoreServiceArg:
if err := recordFirstStartTime(); err != nil {
zap.L().Error("record first start time", zap.Error(err))

return fmt.Errorf("record first start time: %w", err)
}

return runCoreService(cmd.Context(), config, databaseClient, redisClient, networkParamsCaller, settlementCaller)
case WorkerArg:
return runWorker(cmd.Context(), config, databaseClient, streamClient, redisClient)
Expand All @@ -186,6 +178,25 @@ var command = cobra.Command{
},
}

// recordFirstStartTime set the first start time to the current timestamp in seconds if it is not set.
func recordFirstStartTime() error {
// set first start time
firstStartTime, err := info.GetFirstStartTime()
if err != nil {
return fmt.Errorf("get first start time: %w", err)
}

if firstStartTime == 0 {
// update first start time to current timestamp in seconds
err = info.UpdateFirstStartTime(time.Now().Unix())
if err != nil {
return fmt.Errorf("update first start time: %w", err)
}
}

return nil
}

func runCoreService(ctx context.Context, config *config.File, databaseClient database.Client, redisClient rueidis.Client, networkParamsCaller *vsl.NetworkParamsCaller, settlementCaller *vsl.SettlementCaller) error {
server := node.NewCoreService(ctx, config, databaseClient, redisClient, networkParamsCaller, settlementCaller)

Expand Down

0 comments on commit 5d0e688

Please sign in to comment.