From c23f5999160ff47c10983dbd09ce02c2031a22bf Mon Sep 17 00:00:00 2001 From: JT Smith Date: Wed, 15 Jan 2025 16:22:56 -0600 Subject: [PATCH] Aborted jobs now automatically use the EmailRole job handler to email all admins. --- ving/docs/change-log.md | 5 +++++ ving/jobs/worker.mjs | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ving/docs/change-log.md b/ving/docs/change-log.md index 541813b7..ecec7e1c 100644 --- a/ving/docs/change-log.md +++ b/ving/docs/change-log.md @@ -9,6 +9,11 @@ outline: deep * Jobs now automatically retry 3 times and then are aborted. * Fixed: job runner not gracefully erroring #198 * Added better documentation for the job handlers. + * Added generic email template. + * Added EmailRole job handler. + * Aborted jobs now automatically use the EmailRole job handler to email all admins. + * Fixed CLI docs for email. + * Fixed the generator deployment location for email templates. ### 2025-01-14 * Added VingRecord.describeLinks() to generate links for the UI rather than having to manually code them in a describe() override. They are automatically generated for all VingRecords via the CLI, and then pages that are generated also use the exposed links. #179 diff --git a/ving/jobs/worker.mjs b/ving/jobs/worker.mjs index d18b9c59..275dac46 100644 --- a/ving/jobs/worker.mjs +++ b/ving/jobs/worker.mjs @@ -57,10 +57,20 @@ export class VingJobWorker { ving.log('jobs').info(`${job.id} ${job.name} has completed`); }); - this.worker.on('failed', (job, err) => { + this.worker.on('failed', async (job, err) => { ving.log('jobs').error(`${job.id} ${job.name} has errored with ${err.message} using data ${JSON.stringify(job.data)}`); if (job.attemptsMade >= job.opts.attempts) { ving.log('jobs').error(`CRITICAL: ${job.id} ${job.name} aborted after ${job.attemptsMade} attempts`); + await ving.addJob('EmailRole', { + role: 'admin', + subject: `Job ${job.name} aborted`, + message: `Job ${job.name} aborted after ${job.attemptsMade} attempts. + + Job Id: ${job.id} + Error: ${err.message} + Data: + ${JSON.stringify(job.data)}`, + }); } }); ving.log('jobs').info(`worker started`);