Skip to content

Commit

Permalink
feat: one-shot
Browse files Browse the repository at this point in the history
  • Loading branch information
mfw78 committed Sep 26, 2023
1 parent 0313aac commit aad11d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
19 changes: 13 additions & 6 deletions src/modes/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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`,
Expand Down
1 change: 0 additions & 1 deletion src/watchtower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ async function main() {
.option("--loggly-token <logglyToken>", "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,
Expand Down

0 comments on commit aad11d7

Please sign in to comment.