import { Queue } from "bullmq";
import { redisConnectionOpts } from "./connection.js";
import { logger } from "../lib/logger.js";

const log = logger.child({ component: "queues" });

export const mailQueue = new Queue("mail", { connection: redisConnectionOpts });
mailQueue.on("error", (err) => {
  log.error({ queue: "mail", err: err.message }, "Queue error");
});

export const gamificationQueue = new Queue("gamification", {
  connection: redisConnectionOpts,
  defaultJobOptions: { attempts: 3, backoff: { type: "exponential", delay: 2000 } },
});
gamificationQueue.on("error", (err) => {
  log.error({ queue: "gamification", err: err.message }, "Queue error");
});

log.info("Queues initialized");

export const queues: Record<string, Queue> = {
  mail: mailQueue,
  gamification: gamificationQueue,
};
