Skip to content
This repository has been archived by the owner on Dec 20, 2017. It is now read-only.

Commit

Permalink
Moved method setup to job loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
dawnerd committed May 15, 2015
1 parent 966ff00 commit 288c170
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/index.js
Expand Up @@ -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,
Expand Down Expand Up @@ -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});
Expand Down Expand Up @@ -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});
Expand Down

0 comments on commit 288c170

Please sign in to comment.