Skip to content

Commit 8e1fe23

Browse files
sampathBlamsimison
authored andcommitted
fix: Add try/catch block to agenda#now method (#876)
- Enclose agenda#now with try catch as it is an async method - throw error in case of an error in creating/saving the job.
1 parent e18b900 commit 8e1fe23

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/agenda/now.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,21 @@ const noCallback = require('../no-callback');
88
* @function
99
* @param {String} name name of job to schedule
1010
* @param {Object} data data to pass to job
11-
* @returns {Job} new job instance created
11+
* @returns {Promise} resolves with the new job instance created
1212
*/
1313
module.exports = async function(name, data) {
14-
// eslint-disable-next-line prefer-rest-params
15-
noCallback(arguments, 2);
1614
debug('Agenda.now(%s, [Object])', name);
17-
const job = this.create(name, data);
15+
try {
16+
// eslint-disable-next-line prefer-rest-params
17+
noCallback(arguments, 2);
18+
const job = this.create(name, data);
1819

19-
job.schedule(new Date());
20-
await job.save();
20+
job.schedule(new Date());
21+
await job.save();
2122

22-
return job;
23+
return job;
24+
} catch (err) {
25+
debug('error trying to create a job for this exact moment');
26+
throw err;
27+
}
2328
};

0 commit comments

Comments
 (0)