eletrotupi / tcc/ commit / afb7b64

api: log an worker error instead of swallowing it silently

Pedro Lucas Porcellis porcellis@eletrotupi.com 1 month ago afb7b64baf7b4f3792bf21f1079f35bdb0b62135
Parents: 12c613c
1 file(s) changed
  • api/src/lib/queue/WorkerRegistry.ts +4 -0
api/src/lib/queue/WorkerRegistry.ts
1 1
import { Worker, WorkerOptions, Processor } from "bullmq";
2 2
import { getQueue, QueueName } from "@app/lib/queue/QueueRegistry";
3 3
import { mailProcessor } from "@app/lib/queue/processors/mail";
4 4
import { insightProcessor } from "@app/lib/queue/processors/insights";
5 5
import { medicineReminderProcessor } from "@app/lib/queue/processors/medicineReminders";
▸ 36 unchanged lines
42 42

43 43
    worker.on("failed", (job, err) => {
44 44
      console.error(`[${queueName}] job ${job?.id} failed:`, err.message);
45 45
    });
46 46

47 +
    worker.on("error", (err) => {
48 +
      console.error(`[${queueName}] worker error:`, err.message);
49 +
    });
50 +

47 51
    workers.push(worker);
48 52
  }
49 53
}
50 54

51 55
export async function scheduleInsights(): Promise<void> {
▸ 9 unchanged lines
61 65
}
62 66

63 67
export async function closeAllWorkers(): Promise<void> {
64 68
  await Promise.all(workers.map((w) => w.close()));
65 69
}