A powerful and extendable Discord bot, with it's own module system :3
thevoid.cafe/projects/voidy
1import { Queue, Worker, type Job } from "bullmq";
2
3const connection = {
4 host: Bun.env.REDIS_HOST ?? "localhost",
5 port: Number(Bun.env.REDIS_PORT ?? 6379),
6};
7
8export const notificationQueue = new Queue("notifications", {
9 connection,
10 defaultJobOptions: {
11 removeOnComplete: true,
12 removeOnFail: 100,
13 },
14});
15
16export function createNotificationWorker(
17 processor: (job: Job) => Promise<void>,
18): Worker {
19 return new Worker("notifications", processor, {
20 connection,
21 concurrency: 1,
22 limiter: {
23 max: 1,
24 duration: 2000, // 1 job per 2 seconds
25 },
26 });
27}
28
29export async function enqueueNotification(
30 id: string,
31 data: Record<string, unknown>,
32): Promise<void> {
33 await notificationQueue.add(id, { notificationId: id, ...data });
34}