diff --git a/lib/index.js b/lib/index.js index 991f2dc..03f4ebd 100644 --- a/lib/index.js +++ b/lib/index.js @@ -72,10 +72,6 @@ exports.register = function(plugin, options, next) { nextRun = self.jobs[job.name].nextRun; } - if (typeof job.method ==='string') { - job.method = plugin.methods[job.method]; - } - self.collection.update({ name: job.name }, { name: job.name, tasks: job.tasks, @@ -181,7 +177,13 @@ exports.register = function(plugin, options, next) { var startTime = +new Date(); async.eachLimit(data, self.settings.concurrentTasks, function(task, cb) { - self.jobs[job].method.call(plugin, task, cb); + var method = self.jobs[job].method; + + if (typeof method === 'string') { + method = plugin.methods[method]; + } + + method.call(plugin, task, cb); }, function(jobError) { if (jobError) { plugin.log(['hapi-job-queue', 'error'], {error: err}); @@ -284,7 +286,13 @@ exports.register = function(plugin, options, next) { } async.eachLimit(tasks, self.settings.concurrentTasks, function(task, cb) { - self.jobs[job].method.call(plugin, task, cb); + var method = self.jobs[job].method; + + if (typeof method === 'string') { + method = plugin.methods[method]; + } + + method.call(plugin, task, cb); }, function(err) { if (err) { plugin.log(['hapi-job-queue', 'error'], {error: err});