Skip to content

Commit

Permalink
Merge pull request #1 from jesse-matsec/timeouts
Browse files Browse the repository at this point in the history
Add timeouts for old ack requests
  • Loading branch information
rmnoon authored Jan 12, 2023
2 parents fda7b81 + fb81b96 commit 4652a63
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/api/_acks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ const REMINDER_FREQUENCY_MS = REMINDER_FREQUENCY_MIN * 60 * 1000;

const DEBUG_CHECK_ALL = false;

const TIMEOUT_INTERVAL = 30 * 24 * 60 * 60 * 1000; // Default timeout interval for ackbot message checking is 30d

export async function checkForReminders() {
const now = new Date().getTime();
const upperBound = DEBUG_CHECK_ALL ? '+inf' : now - REMINDER_FREQUENCY_MS;
console.log('checkForReminders started: ', { now, upperBound });
console.log('checkForReminders started: ', { now: now, upperBound });

const vals = await redis.zrange(REDIS_ACK_KEY, '-inf', upperBound, { byScore: true }) as string[];
console.log('checkForReminders got reminders: ', { now, vals });
console.log('checkForReminders got reminders: ', { now: now, vals });

const complete: { channel: string, ts: string }[] = [];
const incomplete: { channel: string, ts: string }[] = [];
Expand All @@ -32,7 +34,10 @@ export async function checkForReminders() {
const { isComplete } = await checkMessageAcks(channel, ts, false);
if (isComplete) {
complete.push({ channel, ts });
} else {
} else if ( now > parseInt(ts, 10) + TIMEOUT_INTERVAL ) { // At execution, check if the present time is after the day and time of the original message + 30 days, if so, mark the message as complete (because of timeout)
complete.push({ channel, ts });
}
else {
incomplete.push({ channel, ts });
}
} catch (e) {
Expand All @@ -47,8 +52,8 @@ export async function checkForReminders() {
if (incomplete.length > 0) {
await saveReminders(incomplete);
}
console.log('checkForReminders done: ', { vals, complete, incomplete, now, upperBound });
return { vals, complete, incomplete, now, upperBound };
console.log('checkForReminders done: ', { vals, complete, incomplete, now: now, upperBound });
return { vals, complete, incomplete, now: now, upperBound };
}

async function saveReminders(reminders: { channel: string, ts: string }[]): Promise<void> {
Expand Down

1 comment on commit 4652a63

@vercel
Copy link

@vercel vercel bot commented on 4652a63 Jan 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ackbot – ./

ackbot-stellar8.vercel.app
ackbot.vercel.app
ackbot-git-main-stellar8.vercel.app

Please sign in to comment.