Skip to content

Commit

Permalink
redis again
Browse files Browse the repository at this point in the history
  • Loading branch information
rmnoon committed Jun 21, 2022
1 parent 8afeafb commit 11e75a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
31 changes: 17 additions & 14 deletions src/api/_acks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@ export async function checkForReminders() {
const vals = await redis.zrange(REDIS_ACK_KEY, '-inf', now - REMINDER_FREQUENCY_MS, { byScore: true }) as string[];

console.log('checkForReminders: ', { vals });
const complete: string[] = [];
// const complete: string[] = [];

// check each of them
map(vals, async val => {
const [channel, ts] = val.split(':');
try {
const { isComplete } = await checkMessageAcks(channel, ts);
if (isComplete) {
complete.push(val);
}
} catch (e) {
console.error('checkForReminders error: ', { error: e, val });
}
}, DEFAULT_CONCURRENCY);
// map(vals, async val => {
// const [channel, ts] = val.split(':');
// try {
// const { isComplete } = await checkMessageAcks(channel, ts);
// if (isComplete) {
// complete.push(val);
// }
// } catch (e) {
// console.error('checkForReminders error: ', { error: e, val });
// }
// }, DEFAULT_CONCURRENCY);

// remove any that are now complete
await redis.zrem(REDIS_ACK_KEY, ...complete);
// await redis.zrem(REDIS_ACK_KEY, ...complete);
}

export async function saveReminder(channel: string, ts: string): Promise<void> {
async function saveReminder(channel: string, ts: string): Promise<void> {
await redis.zadd(REDIS_ACK_KEY, { score: new Date().getTime(), member: `${channel}:${ts}` });
}

Expand Down Expand Up @@ -129,6 +129,9 @@ export async function checkMessageAcks(channel: string, ts: string): Promise<{ i
}, DEFAULT_CONCURRENCY);

const isComplete = usersToPing.length === 0;
if (!isComplete) {
await saveReminder(channel, ts);
}
return { isComplete };
}

Expand Down
8 changes: 3 additions & 5 deletions src/api/_constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ export const redis = new Redis({
token: process.env.UPSTASH_REDIS_REST_TOKEN,
});

const pgOptions = {
export const sql = postgres({
host: process.env.PGHOST,
database: process.env.PGDATABASE,
username: process.env.PGUSER,
password: process.env.PGPASSWORD,
ssl: 'require' as const,
};
console.log('pg: ', { pgOptions});
export const sql = postgres(pgOptions);
ssl: 'require',
});

export const slack = new WebClient(process.env.SLACK_BOT_TOKEN);

1 comment on commit 11e75a2

@vercel
Copy link

@vercel vercel bot commented on 11e75a2 Jun 21, 2022

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.vercel.app
ackbot-rmnoon.vercel.app
ackbot-git-main-rmnoon.vercel.app

Please sign in to comment.