Skip to content

Commit

Permalink
feat: Sleep on failure or no messages
Browse files Browse the repository at this point in the history
  • Loading branch information
morgsmccauley committed Sep 15, 2023
1 parent a6d96ee commit 49a3a4b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions runner/src/stream-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export default class StreamHandler {
}

if (!isMainThread) {
const sleep = async (ms: number): Promise<void> => { await new Promise((resolve) => setTimeout(resolve, ms)); };

void (async function main () {
const indexer = new Indexer('mainnet');
const redisClient = new RedisClient();
Expand All @@ -56,6 +58,7 @@ if (!isMainThread) {
indexerName = `${indexerConfig.account_id}/${indexerConfig.function_name}`;

if (messages == null) {
await sleep(1000);
continue;
}

Expand Down Expand Up @@ -92,6 +95,7 @@ if (!isMainThread) {

console.log(`Success: ${indexerName}`);
} catch (err) {
await sleep(10000);
console.log(`Failed: ${indexerName}`, err);
}
}
Expand Down

0 comments on commit 49a3a4b

Please sign in to comment.