feat: add structured logging to BullMQ queues and workers
All checks were successful
Build and Push Backend Image / build (push) Successful in 43s
All checks were successful
Build and Push Backend Image / build (push) Successful in 43s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,17 @@
|
|||||||
import { Queue } from "bullmq";
|
import { Queue } from "bullmq";
|
||||||
import { redisConnectionOpts } from "./connection.js";
|
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 });
|
export const mailQueue = new Queue("mail", { connection: redisConnectionOpts });
|
||||||
|
|
||||||
|
mailQueue.on("error", (err) => {
|
||||||
|
log.error({ queue: "mail", err: err.message }, "Queue error");
|
||||||
|
});
|
||||||
|
|
||||||
|
log.info("Mail queue initialized");
|
||||||
|
|
||||||
export const queues: Record<string, Queue> = {
|
export const queues: Record<string, Queue> = {
|
||||||
mail: mailQueue,
|
mail: mailQueue,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
import { Worker } from "bullmq";
|
import { Worker } from "bullmq";
|
||||||
import { redisConnectionOpts } from "../connection.js";
|
import { redisConnectionOpts } from "../connection.js";
|
||||||
import { sendVerification, sendPasswordReset } from "../../lib/email.js";
|
import { sendVerification, sendPasswordReset } from "../../lib/email.js";
|
||||||
|
import { logger } from "../../lib/logger.js";
|
||||||
|
|
||||||
|
const log = logger.child({ component: "mail-worker" });
|
||||||
|
|
||||||
export function startMailWorker(): Worker {
|
export function startMailWorker(): Worker {
|
||||||
const worker = new Worker(
|
const worker = new Worker(
|
||||||
"mail",
|
"mail",
|
||||||
async (job) => {
|
async (job) => {
|
||||||
|
log.info({ jobId: job.id, jobName: job.name }, `Processing mail job`);
|
||||||
switch (job.name) {
|
switch (job.name) {
|
||||||
case "sendVerification":
|
case "sendVerification":
|
||||||
await sendVerification(job.data.email as string, job.data.token as string);
|
await sendVerification(job.data.email as string, job.data.token as string);
|
||||||
@@ -16,12 +20,13 @@ export function startMailWorker(): Worker {
|
|||||||
default:
|
default:
|
||||||
throw new Error(`Unknown mail job: ${job.name}`);
|
throw new Error(`Unknown mail job: ${job.name}`);
|
||||||
}
|
}
|
||||||
|
log.info({ jobId: job.id, jobName: job.name }, `Mail job completed`);
|
||||||
},
|
},
|
||||||
{ connection: redisConnectionOpts },
|
{ connection: redisConnectionOpts },
|
||||||
);
|
);
|
||||||
|
|
||||||
worker.on("failed", (job, err) => {
|
worker.on("failed", (job, err) => {
|
||||||
console.error(`Mail job ${job?.id} (${job?.name}) failed:`, err.message);
|
log.error({ jobId: job?.id, jobName: job?.name, err: err.message }, `Mail job failed`);
|
||||||
});
|
});
|
||||||
|
|
||||||
return worker;
|
return worker;
|
||||||
|
|||||||
Reference in New Issue
Block a user