From aad11d75341d5ee5f2d6f469ee557e6ce7d9be33 Mon Sep 17 00:00:00 2001 From: mfw78 Date: Fri, 22 Sep 2023 05:21:08 +0000 Subject: [PATCH] feat: one-shot --- src/modes/run.ts | 19 +++++++++++++------ src/watchtower.ts | 1 - 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/modes/run.ts b/src/modes/run.ts index a3dea1d..bead4b2 100644 --- a/src/modes/run.ts +++ b/src/modes/run.ts @@ -12,7 +12,7 @@ import { checkForAndPlaceOrder } from "../checkForAndPlaceOrder"; * @param options Specified by the CLI / environment for running the watch-tower */ export async function run(options: RunOptions) { - const { rpc, deploymentBlock } = options; + const { rpc, deploymentBlock, oneShot } = options; process.on("unhandledRejection", async (error) => { console.log(error); @@ -42,7 +42,7 @@ export async function run(options: RunOptions) { // Run the block watcher for each chain const runPromises = chainWatchers.map(async (chainWatcher) => { - return chainWatcher.warmUp(); + return chainWatcher.warmUp(oneShot); }); // Run all the chain watchers @@ -104,7 +104,7 @@ export class ChainWatcher { * checking if the chain is in sync. * @returns the run promises for what needs to be watched */ - public async warmUp() { + public async warmUp(oneShot?: boolean) { const { provider, chainId } = this.chainContext; const { lastProcessedBlock } = this.registry; const { pageSize } = this; @@ -202,8 +202,18 @@ export class ChainWatcher { } } while (!this.inSync); + _(oneShot ? "Chain watcher is in sync" : "Chain watcher is warmed up"); + _(`Last processed block: ${this.registry.lastProcessedBlock}`); + // Notifying that the chain watcher is in sync this.inSync = true; + + // If one-shot, return + if (oneShot) { + return; + } + + // Otherwise, run the block watcher return await this.runBlockWatcher(); } @@ -236,9 +246,6 @@ export class ChainWatcher { ); } _(`Block ${blockNumber} has been processed.`); - - await new Promise((resolve) => setTimeout(resolve, 1000)); - // await processBlock(provider, blockNumber, chainId, testRuntime); } catch (error) { console.error( `[runBlockWatcher:chainId:${chainId}] Error in processBlock`, diff --git a/src/watchtower.ts b/src/watchtower.ts index fe307dc..a5d016c 100644 --- a/src/watchtower.ts +++ b/src/watchtower.ts @@ -36,7 +36,6 @@ async function main() { .option("--loggly-token ", "Loggly token") .option("--one-shot", "Run the watchtower once and exit", false) .action((options) => { - // Need to assert that the RPCs and deployment blocks are the same length const { rpc, deploymentBlock: deploymentBlockEnv,