Skip to content

Commit

Permalink
Aborted jobs now automatically use the EmailRole job handler to email…
Browse files Browse the repository at this point in the history
… all admins.
  • Loading branch information
rizen committed Jan 15, 2025
1 parent 25011db commit c23f599
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ving/docs/change-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion ving/jobs/worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down

0 comments on commit c23f599

Please sign in to comment.