Skip to content

Commit

Permalink
fix: Add try/catch block to agenda#now method (#876)
Browse files Browse the repository at this point in the history
- Enclose agenda#now with try catch as it is an async method
- throw error in case of an error in creating/saving the job.
  • Loading branch information
sampathBlam authored and simison committed Nov 24, 2019
1 parent e18b900 commit 8e1fe23
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/agenda/now.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@ const noCallback = require('../no-callback');
* @function
* @param {String} name name of job to schedule
* @param {Object} data data to pass to job
* @returns {Job} new job instance created
* @returns {Promise} resolves with the new job instance created
*/
module.exports = async function(name, data) {
// eslint-disable-next-line prefer-rest-params
noCallback(arguments, 2);
debug('Agenda.now(%s, [Object])', name);
const job = this.create(name, data);
try {
// eslint-disable-next-line prefer-rest-params
noCallback(arguments, 2);
const job = this.create(name, data);

job.schedule(new Date());
await job.save();
job.schedule(new Date());
await job.save();

return job;
return job;
} catch (err) {
debug('error trying to create a job for this exact moment');
throw err;
}
};

0 comments on commit 8e1fe23

Please sign in to comment.