From f7c50ef478b906be9d0db2b555c148641a03a7b9 Mon Sep 17 00:00:00 2001 From: Hugo Cornu Date: Thu, 30 Jun 2016 08:11:29 +0200 Subject: [PATCH] issue-19-patch (#25) * Update agendash.js --- lib/agendash.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/agendash.js b/lib/agendash.js index 9b49a444..2ddbc338 100644 --- a/lib/agendash.js +++ b/lib/agendash.js @@ -81,15 +81,23 @@ module.exports = function (agenda, options) { /* TODO: Need to validate user input. */ - agenda.create(jobName,jobData) - .schedule(jobSchedule) - .repeatEvery(jobRepeatEvery) - .save(function (err) { - if (err) { - callback('Jobs not created') - } - callback() - }); + var job = agenda.create(jobName,jobData) + if (jobSchedule && jobRepeatEvery) { + job.repeatAt(jobSchedule) + job.repeatEvery(jobRepeatEvery) + } else if (jobSchedule) { + job.schedule(jobSchedule) + } else if (jobRepeatEvery) { + job.repeatEvery(jobRepeatEvery) + } else { + return callback('Jobs not created') + } + job.save(function (err) { + if (err) { + return callback('Jobs not created') + } + callback() + }); } catch (e) { callback(e.message) }