Skip to content

Commit

Permalink
watcher: use a while loop
Browse files Browse the repository at this point in the history
  • Loading branch information
panoel committed Jun 11, 2024
1 parent 49bc239 commit 37c1f6c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions watcher/src/workers/supervisor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Worker } from 'worker_threads';
import { HB_INTERVAL, WorkerData } from '../consts';
import { getLogger } from '../utils/logger';
import { Mode, getMode, getNetwork } from '@wormhole-foundation/wormhole-monitor-common';
import { Mode, getMode, getNetwork, sleep } from '@wormhole-foundation/wormhole-monitor-common';
import { Chain, Network } from '@wormhole-foundation/sdk-base';

interface WorkerInfo {
Expand Down Expand Up @@ -39,8 +39,8 @@ function spawnWorker(data: WorkerData) {
logger.debug('Finished spawning worker:', workerName);
}

function monitorWorkers() {
setInterval(async () => {
async function monitorWorkers(): Promise<void> {
while (true) {
for (const [workerName, workerInfo] of Object.entries(workers)) {
logger.debug(
`Checking worker ${workerName} with lastHB of ${new Date(workerInfo.lastHB)}...`
Expand All @@ -52,7 +52,8 @@ function monitorWorkers() {
spawnWorker(workerInfo.data);
}
}
}, HB_INTERVAL);
await sleep(HB_INTERVAL);
}
}

export function startSupervisor(supportedChains: Chain[]) {
Expand Down

0 comments on commit 37c1f6c

Please sign in to comment.