Skip to content

Commit

Permalink
Use finally() after attempting to run worker jobs
Browse files Browse the repository at this point in the history
This prevents now() from being passed an error. Previously, if the
UPDATE to increment the failure count was rejected, now() would be
passed an error, which isn't something it knows how to handle.
  • Loading branch information
matthew-white committed Dec 12, 2023
1 parent 7e0383c commit 5e1c7c1
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/worker/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const { min } = Math;
const { inspect } = require('util');
const { head } = require('ramda');
const { sql } = require('slonik');
const { timebound, resolve, runSequentially } = require('../util/promise');
const { timebound, runSequentially } = require('../util/promise');
const defaultJobMap = require('./jobs').jobs;

// TODO: domain catch/restart? << investigated and seems unlikely.
Expand Down Expand Up @@ -58,10 +58,9 @@ const workerQueue = (container, jobMap = defaultJobMap) => {
.then(() => { process.stdout.write(`[${(new Date()).toISOString()}] finish processing event ${logname}\n`); })
.catch((err) => {
report(err);
return run(sql`update audits set claimed=null, failures=${event.failures + 1}, "lastFailure"=clock_timestamp() where id=${event.id}`)
.then(() => resolve());
return run(sql`update audits set claimed=null, failures=${event.failures + 1}, "lastFailure"=clock_timestamp() where id=${event.id}`);
})
.then(done, done);
.finally(done);

return true;
};
Expand Down

0 comments on commit 5e1c7c1

Please sign in to comment.