From 65488a4ec1c878a9c191923535faa4ebef5ff7f8 Mon Sep 17 00:00:00 2001 From: Matthieu Vachon Date: Tue, 23 Jul 2024 11:35:58 -0400 Subject: [PATCH] Fixed startup delay to happen much higher in the initialization timeline --- CHANGELOG.md | 4 ++++ cmd/substreams-sink-noop/main.go | 13 +++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08da38c..1324748 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## v1.3.1 + +- Move startup delay handling much higher in the initialization so that it happens before anything else. + ## v1.3.0 - Adding `--startup-delay` flag when staring a sink noop. This allows for easier debugging or maintenance on the state on disk. diff --git a/cmd/substreams-sink-noop/main.go b/cmd/substreams-sink-noop/main.go index 04297c5..9d67516 100644 --- a/cmd/substreams-sink-noop/main.go +++ b/cmd/substreams-sink-noop/main.go @@ -77,6 +77,13 @@ func run(cmd *cobra.Command, args []string) error { cancelApp() }) + // The startup delay should be performed before any other initialization otherwise + // sometimes you cannot fix some errors that are happening in `sink.NewFromViper`. + if startUpDelay := sflags.MustGetDuration(cmd, "startup-delay"); startUpDelay > 0 { + zlog.Info("sleeping before starting", zap.Duration("duration", startUpDelay)) + time.Sleep(startUpDelay) + } + endpoint := args[0] manifestPath := args[1] moduleName := args[2] @@ -96,7 +103,6 @@ func run(cmd *cobra.Command, args []string) error { sinker.outputDataHash = newDataHasher(outputInterval) } - startUpDelay := sflags.MustGetDuration(cmd, "startup-delay") apiListenAddr := sflags.MustGetString(cmd, "api-listen-addr") cleanState := sflags.MustGetBool(cmd, "clean") stateStorePath := sflags.MustGetString(cmd, "state-store") @@ -111,11 +117,6 @@ func run(cmd *cobra.Command, args []string) error { zap.String("manage_listen_addr", apiListenAddr), ) - if startUpDelay > 0 { - zlog.Info("sleeping before starting", zap.Duration("duration", startUpDelay)) - time.Sleep(startUpDelay) - } - headTrackerClient, headTrackerConnClose, headTrackerCallOpts, headTrackerHeaders, err := client.NewSubstreamsClient(sinker.ClientConfig()) cli.NoError(err, "Unable to create head tracker client") defer headTrackerConnClose()