@lexamica-modules/job-queue
Version:
The package for the Lexamica Job Queue SDK powered by Redis and BullMQ
52 lines (47 loc) • 1.31 kB
text/typescript
import { TaskLogger } from "@lexamica-modules/logger";
const logger = TaskLogger(
process.env.DATA_DOG_API_KEY ?? "",
"Message-Queue",
process.env.JOB_QUEUE_ENVIRONMENT as string,
"",
);
// handle and log all uncaught errors
process.on("uncaughtException", function (err) {
logger.error(
`An uncaught error occured in the @lexamica-modules/job-queue package: ${err}`,
);
});
process.on("unhandledRejection", (reason, promise) => {
logger.error(
`An unhandled rejection occured in the @lexamica-modules/job-queue package: ${{
promise,
reason,
}}`,
);
});
/**
* This function logs out an error and optionally throws it further if specified
* @param options
* @param {string} options.message The error message to log
* @param {string} options.job The job name or ID
* @param {Error} options.error The actual error being handled
* @param {boolean} options.handle Default to true, but if set to false, error will be thrown through once it has been logged.
*/
export function handleErrorWithInfo({
message,
job,
error,
handle = true,
}: {
message: string;
job: string;
error: Error;
handle?: boolean;
}): void | Error {
logger.error(
`Message Queue Job: ${job} | Message: ${message} | Error: ${error}`,
);
if (!handle) {
throw error;
}
}