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 e82e2ef
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion 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 @@ -47,7 +49,6 @@ if (!isMainThread) {

while (true) {
try {
const startTime = performance.now();
const streamType = redisClient.getStreamType(streamKey);

const messages = await redisClient.getNextStreamMessage(streamKey);
Expand All @@ -56,11 +57,14 @@ if (!isMainThread) {
indexerName = `${indexerConfig.account_id}/${indexerConfig.function_name}`;

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

const [{ id, message }] = messages;

const startTime = performance.now();

const functions = {
[indexerName]: {
account_id: indexerConfig.account_id,
Expand Down Expand Up @@ -92,6 +96,7 @@ if (!isMainThread) {

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

0 comments on commit e82e2ef

Please sign in to comment.