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,11 +1,15 @@
|
||||
import { Worker } from "bullmq";
|
||||
import { redisConnectionOpts } from "../connection.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 {
|
||||
const worker = new Worker(
|
||||
"mail",
|
||||
async (job) => {
|
||||
log.info({ jobId: job.id, jobName: job.name }, `Processing mail job`);
|
||||
switch (job.name) {
|
||||
case "sendVerification":
|
||||
await sendVerification(job.data.email as string, job.data.token as string);
|
||||
@@ -16,12 +20,13 @@ export function startMailWorker(): Worker {
|
||||
default:
|
||||
throw new Error(`Unknown mail job: ${job.name}`);
|
||||
}
|
||||
log.info({ jobId: job.id, jobName: job.name }, `Mail job completed`);
|
||||
},
|
||||
{ connection: redisConnectionOpts },
|
||||
);
|
||||
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user