Skip to content

Commit

Permalink
Closes GH-101: factory never more limits user defined job properties
Browse files Browse the repository at this point in the history
  • Loading branch information
kusor committed Jul 2, 2013
1 parent 289a144 commit ea1ccf9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
32 changes: 20 additions & 12 deletions lib/workflow-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ var WorkflowFactory = module.exports = function (backend) {

return backend.getWorkflow(j.workflow, function (err, wf) {
var p;
var q;
if (err) {
return callback(err);
}
Expand All @@ -187,28 +188,35 @@ var WorkflowFactory = module.exports = function (backend) {
'Cannot queue a job from a workflow without any task');
}

for (p in wf) {
if (p !== 'uuid' && p !== 'chain_md5' && p !== 'onerror_md5') {
theJob[p] = wf[p];
} else {
theJob.workflow_uuid = wf.uuid;
for (q in j) {
if (j !== 'workflow') {
theJob[q] = j[q];
}
}

theJob.exec_after = j.exec_after || new Date().toISOString();
theJob.params = j.params || {};
theJob.num_attempts = j.num_attempts || 0;
if (!theJob.exec_after) {
theJob.exec_after = new Date().toISOString();
}

if (!theJob.params) {
theJob.params = {};
}

if (typeof (j.locks) !== 'undefined') {
theJob.locks = j.locks;
if (!theJob.num_attempts) {
theJob.num_attempts = 0;
}

if (!theJob.uuid) {
theJob.uuid = uuid();
}

if (j.target) {
theJob.target = j.target;

for (p in wf) {
if (p === 'uuid') {
theJob.workflow_uuid = wf.uuid;
} else if (p !== 'chain_md5' && p !== 'onerror_md5') {
theJob[p] = wf[p];
}
}

return backend.validateJobTarget(theJob, function (err) {
Expand Down
9 changes: 7 additions & 2 deletions test/in-memory-backend.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ test('add a workflow', function (t) {
body: function (job, cb) {
return cb('Workflow error');
}
}]
}],
arbitrary: 'Arbitrary property'
}, function (err, workflow) {
t.ifError(err, 'add workflow error');
t.ok(workflow, 'add workflow ok');
aWorkflow = workflow;
t.ok(workflow.chain[0].uuid, 'add workflow chain task');
t.ok(workflow.onerror[0].uuid, 'add workflow onerror task');
t.ok(workflow.arbitrary);
t.end();
});
});
Expand Down Expand Up @@ -127,7 +129,8 @@ test('create job', function (t) {
foo: 'bar',
chicken: 'arise!'
},
locks: 'something$'
locks: 'something$',
whatever: 'test arbitrary job properties'
}, function (err, job) {
t.ifError(err, 'create job error');
t.ok(job, 'create job ok');
Expand All @@ -139,6 +142,8 @@ test('create job', function (t) {
t.ok(
(typeof (job.params) === 'object' && !util.isArray(job.params)),
'params ok');
t.ok(job.whatever);
t.ok(job.arbitrary);
aJob = job;
backend.getJobProperty(aJob.uuid, 'target', function (err, val) {
t.ifError(err, 'get job property error');
Expand Down

0 comments on commit ea1ccf9

Please sign in to comment.