From 5769f61d1be5984ffb49a7984068c7e7d287f9e2 Mon Sep 17 00:00:00 2001 From: belopash Date: Tue, 31 Dec 2024 16:44:01 +0300 Subject: [PATCH] bound metrics chain height with request range --- .../src/runner.ts | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/util/util-internal-processor-tools/src/runner.ts b/util/util-internal-processor-tools/src/runner.ts index b2f9b573f..a3e8f9df7 100644 --- a/util/util-internal-processor-tools/src/runner.ts +++ b/util/util-internal-processor-tools/src/runner.ts @@ -43,7 +43,7 @@ export class Runner { if (this.getLeftRequests(state).length == 0) { this.printProcessingRange() log.info('nothing to do') - return + return this.exit() } this.printProcessingMessage(state) @@ -110,9 +110,11 @@ export class Runner { state = nextState } - return this.processHotBlocks(state).finally( + await this.processHotBlocks(state).finally( this.chainHeightUpdateLoop(hot) ) + + return this.exit() } private async assertWeAreOnTheSameChain(src: DataSource, state: HashAndHeight): Promise { @@ -306,7 +308,8 @@ export class Runner { private async initMetrics(chainHeight: number, state: HotDatabaseState): Promise { let initialized = this.metrics.getChainHeight() >= 0 - this.metrics.setChainHeight(chainHeight) + let boundedChainHeight = Math.min(chainHeight, rangeEnd(last(this.config.requests).range)) + this.metrics.setChainHeight(boundedChainHeight) if (initialized) return this.metrics.setLastProcessedBlock(state.height + state.top.length) this.metrics.updateProgress() @@ -343,6 +346,14 @@ export class Runner { this.log.info(msg) } + private async exit(): Promise { + if (isProcessorExitDisabled()) { + while (true) { + await wait(5000) + } + } + } + @def private async startPrometheusServer(): Promise { let prometheusServer = await this.config.prometheus.serve() @@ -353,3 +364,7 @@ export class Runner { return this.config.log } } + +function isProcessorExitDisabled() { + return process.env.SQUID_PROCESSOR_EXIT_DISABLED === 'true' +} \ No newline at end of file