-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathqueues.ts
More file actions
35 lines (32 loc) · 1023 Bytes
/
queues.ts
File metadata and controls
35 lines (32 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import type { Job, JobsOptions, Worker } from "bullmq";
import { env } from "../../shared/utils/env";
import { logger } from "../../shared/utils/logger";
export const defaultJobOptions: JobsOptions = {
// Does not retry by default. Queues must explicitly define their own retry count and backoff behavior.
attempts: 0,
removeOnComplete: {
age: env.QUEUE_JOB_RETENTION_AGE_SECONDS,
count: env.QUEUE_COMPLETE_HISTORY_COUNT,
},
removeOnFail: {
age: env.QUEUE_JOB_RETENTION_AGE_SECONDS,
count: env.QUEUE_FAIL_HISTORY_COUNT,
},
};
export const logWorkerExceptions = (worker: Worker) => {
worker.on("failed", (job: Job | undefined, err: Error) => {
if (!job) {
return;
}
job.log(`Job failed: ${err.message}`);
logger({
level: "error",
message: `[${worker.name}] Job failed. jobId="${job.id}" data="${
job.data
}", error="${err.message}" ${
env.NODE_ENV === "development" ? err.stack : ""
}`,
service: "worker",
});
});
};