rethinkdb-job-queue
Advanced tools
Comparing version 2.1.1 to 2.2.0
@@ -10,2 +10,3 @@ 'use strict'; | ||
var jobCompleted = require('./job-completed'); | ||
var jobUpdate = require('./job-update'); | ||
var queueCancelJob = require('./queue-cancel-job'); | ||
@@ -86,15 +87,24 @@ var jobFailed = require('./job-failed'); | ||
var returnPromise = void 0; | ||
if (err) { | ||
function setJobStatusToWaiting() { | ||
logger('Invalid job status', job.status); | ||
logger('Setting job status to: ' + enums.status.waiting); | ||
job.status = enums.status.waiting; | ||
} | ||
function errAction(err) { | ||
logger('jobResult is an error'); | ||
if (err.cancelJob) { | ||
returnPromise = queueCancelJob(job.q, job, err.cancelJob); | ||
} else { | ||
returnPromise = jobFailed(job, err); | ||
} | ||
} else { | ||
logger('jobResult processed successfully'); | ||
returnPromise = jobCompleted(job, jobResult); | ||
err.cancelJob && logger('Job is being cancelled'); | ||
return err.cancelJob ? queueCancelJob(job.q, job, err.cancelJob) : jobFailed(job, err); | ||
} | ||
function resultAction(result) { | ||
logger('jobResult is valid'); | ||
var resultIsJob = is.job(result) && is.object(result.q); | ||
result.status === enums.status.active && setJobStatusToWaiting(); | ||
resultIsJob && logger('Job is being updated'); | ||
return resultIsJob ? jobUpdate(result) : jobCompleted(job, result); | ||
} | ||
var returnPromise = err ? errAction(err) : resultAction(jobResult); | ||
return returnPromise.then(function (finalResult) { | ||
@@ -101,0 +111,0 @@ job.q._running--; |
{ | ||
"name": "rethinkdb-job-queue", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"description": "A persistent job or task queue backed by RethinkDB.", | ||
@@ -37,4 +37,4 @@ "main": "index.js", | ||
"build": "npm run clean && babel src --presets babel-preset-latest --out-dir dist", | ||
"test": "tap --timeout 1000 ./tests/test-runner.js", | ||
"tv": "tap --timeout 1000 --reporter tap ./tests/test-runner.js", | ||
"test": "tap --timeout 10000 ./tests/test-runner.js", | ||
"tv": "tap --timeout 10000 --reporter tap ./tests/test-runner.js", | ||
"tc": "node ./tests/test-current.js", | ||
@@ -68,8 +68,8 @@ "tcd": "node --inspect --debug-brk ./tests/test-current.js", | ||
"istanbul": "0.4.5", | ||
"npm-check-updates": "^2.8.9", | ||
"npm-check-updates": "^2.8.10", | ||
"proxyquire": "^1.7.11", | ||
"standard": "^8.6.0", | ||
"tap-spec": "^4.1.1", | ||
"tap": "^9.0.3" | ||
"tap": "^10.0.2" | ||
} | ||
} |
@@ -18,3 +18,3 @@ const test = require('tap').test | ||
test(testName, { timeout: 200000 }, (t) => { | ||
t.plan(409) | ||
t.plan(418) | ||
@@ -44,3 +44,3 @@ // ---------- Test Setup ---------- | ||
ready: 0, | ||
processing: 48, | ||
processing: 49, | ||
progress: 1, | ||
@@ -50,3 +50,3 @@ pausing: 14, | ||
resumed: 14, | ||
removed: 0, | ||
removed: 1, | ||
idle: 12, | ||
@@ -60,5 +60,5 @@ reset: 0, | ||
dropped: 0, | ||
added: 37, | ||
added: 38, | ||
waiting: 0, | ||
active: 48, | ||
active: 49, | ||
completed: 42, | ||
@@ -70,3 +70,3 @@ cancelled: 3, | ||
log: 0, | ||
updated: 0 | ||
updated: 1 | ||
} | ||
@@ -89,2 +89,3 @@ | ||
let testCancel = false | ||
let updateJob = false | ||
let jobProcessTimeoutId = false | ||
@@ -105,2 +106,5 @@ | ||
next(cancelErr) | ||
} else if (updateJob) { | ||
job.updateNote = tData | ||
next(null, job) | ||
} else { | ||
@@ -243,4 +247,18 @@ if (updateProgress) { | ||
}).then(() => { | ||
// // TODO - Remove below to run all tests. | ||
// return q.stop().then(() => Promise.reject()) | ||
// | ||
// ---------- Processing with Job Update Test ---------- | ||
t.comment('queue-process: Processing with Job Update') | ||
updateJob = true | ||
jobs = q.createJob() | ||
return q.addJob(jobs) | ||
}).delay(1000).then(() => { | ||
return q.getJob(jobs) | ||
}).then((updatedJob) => { | ||
t.equal(updatedJob[0].updateNote, tData, 'Job updated in next() call successfully') | ||
t.equal(updatedJob[0].status, enums.status.waiting, 'Job status is waiting') | ||
t.equal(updatedJob[0].getLastLog().message, enums.message.jobUpdated, 'Job updated log entry valid') | ||
return q.removeJob(updatedJob[0]) | ||
}).then(() => { | ||
updateJob = false | ||
// | ||
// ---------- Processing Restart on Job Add Test ---------- | ||
@@ -247,0 +265,0 @@ t.comment('queue-process: Process Restart on Job Add') |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
549330
7690