Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: notify admins when a thread has 100 messages 🚨 #605

Merged
merged 3 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { db } from '@oyster/db';

import { job } from '@/infrastructure/bull/use-cases/job';

export async function notifyBusySlackThread(threadId: string) {
const row = await db
.selectFrom('slackMessages')
.select((eb) => [eb.fn.countAll<string>().as('count'), 'channelId']) // channelId is needed for the message link
.where('threadId', '=', threadId)
.executeTakeFirstOrThrow();

const count = Number(row.count);

if (count == 100) {
const channelId = row.channelId;
const uri = `https://colorstack-family.slack.com/archives/${channelId}/p${threadId}`;
const message = `
🚨 Uh-oh! Thread <${uri}|#${threadId}> has gone over πŸ’― replies!
Better see what's going on. πŸ‘€
`;

job('notification.slack.send', {
message: message,
workspace: 'internal',
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { type GetBullJobData } from '@/infrastructure/bull/bull.types';
import { job } from '@/infrastructure/bull/use-cases/job';
import { redis } from '@/infrastructure/redis';
import { isFeatureFlagEnabled } from '@/modules/feature-flag/queries/is-feature-flag-enabled';
import { notifyBusySlackThread } from '@/modules/slack/queries/notify-busy-slack-thread';
import { ErrorWithContext } from '@/shared/errors';
import { retryWithBackoff } from '@/shared/utils/core.utils';
import { getSlackMessage } from '../services/slack-message.service';
Expand Down Expand Up @@ -45,6 +46,8 @@ export async function addSlackMessage(
threadRepliedTo: data.threadId,
type: 'reply_to_thread',
});

notifyBusySlackThread(data.threadId);
}
}

Expand Down
Loading