rethinkdb-job-queue
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -12,3 +12,3 @@ 'use strict'; | ||
module.exports = function queueGetJob(q, jobOrId) { | ||
module.exports = function queueReanimateJob(q, jobOrId) { | ||
var dateEnable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Date(); | ||
@@ -33,4 +33,4 @@ | ||
logger('jobsResult', jobsResult); | ||
return dbResult.toJob(q, jobsResult); | ||
}).then(function (reanimatedJobs) { | ||
return dbResult.toIds(jobsResult); | ||
}).then(function (reanimatedJobIds) { | ||
var _iteratorNormalCompletion = true; | ||
@@ -41,7 +41,7 @@ var _didIteratorError = false; | ||
try { | ||
for (var _iterator = reanimatedJobs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var reanimatedJob = _step.value; | ||
for (var _iterator = reanimatedJobIds[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var reanimatedJobId = _step.value; | ||
logger('Event: reanimated', q.id, reanimatedJob.id); | ||
q.emit(enums.status.reanimated, q.id, reanimatedJob.id); | ||
logger('Event: reanimated', q.id, reanimatedJobId); | ||
q.emit(enums.status.reanimated, q.id, reanimatedJobId); | ||
} | ||
@@ -63,4 +63,4 @@ } catch (err) { | ||
return reanimatedJobs; | ||
return reanimatedJobIds; | ||
}); | ||
}; |
@@ -25,2 +25,3 @@ 'use strict'; | ||
var queueCancelJob = require('./queue-cancel-job'); | ||
var queueReanimateJob = require('./queue-reanimate-job'); | ||
var queueRemoveJob = require('./queue-remove-job'); | ||
@@ -133,12 +134,26 @@ var queueReset = require('./queue-reset'); | ||
}, { | ||
key: 'reanimateJob', | ||
value: function reanimateJob(jobOrId, dateEnable) { | ||
var _this6 = this; | ||
logger('reanimateJob', jobOrId, dateEnable); | ||
return this.ready().then(function () { | ||
return queueReanimateJob(_this6, jobOrId, dateEnable); | ||
}).catch(function (err) { | ||
logger('Event: reanimateJob error', _this6.id, err); | ||
_this6.emit(enums.status.error, _this6.id, err); | ||
return Promise.reject(err); | ||
}); | ||
} | ||
}, { | ||
key: 'removeJob', | ||
value: function removeJob(jobOrId) { | ||
var _this6 = this; | ||
var _this7 = this; | ||
logger('removeJob', jobOrId); | ||
return this.ready().then(function () { | ||
return queueRemoveJob(_this6, jobOrId); | ||
return queueRemoveJob(_this7, jobOrId); | ||
}).catch(function (err) { | ||
logger('Event: removeJob error', _this6.id, err); | ||
_this6.emit(enums.status.error, _this6.id, err); | ||
logger('Event: removeJob error', _this7.id, err); | ||
_this7.emit(enums.status.error, _this7.id, err); | ||
return Promise.reject(err); | ||
@@ -150,10 +165,10 @@ }); | ||
value: function process(handler) { | ||
var _this7 = this; | ||
var _this8 = this; | ||
logger('process', handler); | ||
return this.ready().then(function () { | ||
return queueProcess.addHandler(_this7, handler); | ||
return queueProcess.addHandler(_this8, handler); | ||
}).catch(function (err) { | ||
logger('Event: process error', _this7.id, err); | ||
_this7.emit(enums.status.error, _this7.id, err); | ||
logger('Event: process error', _this8.id, err); | ||
_this8.emit(enums.status.error, _this8.id, err); | ||
return Promise.reject(err); | ||
@@ -165,10 +180,10 @@ }); | ||
value: function review() { | ||
var _this8 = this; | ||
var _this9 = this; | ||
logger('review'); | ||
return this.ready().then(function () { | ||
return dbReview.runOnce(_this8); | ||
return dbReview.runOnce(_this9); | ||
}).catch(function (err) { | ||
logger('Event: review error', _this8.id, err); | ||
_this8.emit(enums.status.error, _this8.id, err); | ||
logger('Event: review error', _this9.id, err); | ||
_this9.emit(enums.status.error, _this9.id, err); | ||
return Promise.reject(err); | ||
@@ -180,10 +195,10 @@ }); | ||
value: function summary() { | ||
var _this9 = this; | ||
var _this10 = this; | ||
logger('summary'); | ||
return this.ready().then(function () { | ||
return queueSummary(_this9); | ||
return queueSummary(_this10); | ||
}).catch(function (err) { | ||
logger('Event: summary error', _this9.id, err); | ||
_this9.emit(enums.status.error, _this9.id, err); | ||
logger('Event: summary error', _this10.id, err); | ||
_this10.emit(enums.status.error, _this10.id, err); | ||
return Promise.reject(err); | ||
@@ -201,10 +216,10 @@ }); | ||
value: function pause(global) { | ||
var _this10 = this; | ||
var _this11 = this; | ||
logger('pause'); | ||
return this.ready().then(function () { | ||
return queueInterruption.pause(_this10, global); | ||
return queueInterruption.pause(_this11, global); | ||
}).catch(function (err) { | ||
logger('Event: pause error', _this10.id, err); | ||
_this10.emit(enums.status.error, _this10.id, err); | ||
logger('Event: pause error', _this11.id, err); | ||
_this11.emit(enums.status.error, _this11.id, err); | ||
return Promise.reject(err); | ||
@@ -216,10 +231,10 @@ }); | ||
value: function resume(global) { | ||
var _this11 = this; | ||
var _this12 = this; | ||
logger('resume'); | ||
return this.ready().then(function () { | ||
return queueInterruption.resume(_this11, global); | ||
return queueInterruption.resume(_this12, global); | ||
}).catch(function (err) { | ||
logger('Event: resume error', _this11.id, err); | ||
_this11.emit(enums.status.error, _this11.id, err); | ||
logger('Event: resume error', _this12.id, err); | ||
_this12.emit(enums.status.error, _this12.id, err); | ||
return Promise.reject(err); | ||
@@ -231,10 +246,10 @@ }); | ||
value: function reset() { | ||
var _this12 = this; | ||
var _this13 = this; | ||
logger('reset'); | ||
return this.ready().then(function () { | ||
return queueReset(_this12); | ||
return queueReset(_this13); | ||
}).catch(function (err) { | ||
logger('Event: reset error', _this12.id, err); | ||
_this12.emit(enums.status.error, _this12.id, err); | ||
logger('Event: reset error', _this13.id, err); | ||
_this13.emit(enums.status.error, _this13.id, err); | ||
return Promise.reject(err); | ||
@@ -246,10 +261,10 @@ }); | ||
value: function stop() { | ||
var _this13 = this; | ||
var _this14 = this; | ||
logger('stop'); | ||
return queueStop(this).then(function () { | ||
return queueDb.drain(_this13); | ||
return queueDb.drain(_this14); | ||
}).catch(function (err) { | ||
logger('Event: stop error', _this13.id, err); | ||
_this13.emit(enums.status.error, _this13.id, err); | ||
logger('Event: stop error', _this14.id, err); | ||
_this14.emit(enums.status.error, _this14.id, err); | ||
return Promise.reject(err); | ||
@@ -261,8 +276,8 @@ }); | ||
value: function drop() { | ||
var _this14 = this; | ||
var _this15 = this; | ||
logger('drop'); | ||
return queueDrop(this).catch(function (err) { | ||
logger('Event: drop error', _this14.id, err); | ||
_this14.emit(enums.status.error, _this14.id, err); | ||
logger('Event: drop error', _this15.id, err); | ||
_this15.emit(enums.status.error, _this15.id, err); | ||
return Promise.reject(err); | ||
@@ -269,0 +284,0 @@ }); |
{ | ||
"name": "rethinkdb-job-queue", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "A persistent job or task queue backed by RethinkDB.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -15,3 +15,3 @@ const test = require('tap').test | ||
test(testName, (t) => { | ||
t.plan(48) | ||
t.plan(49) | ||
@@ -88,2 +88,5 @@ // ---------- Test Setup ---------- | ||
}).then((result) => { | ||
t.ok(is.uuid(result[0]), 'Reanimate jobs returns job ids') | ||
return q.getJob(job.id) | ||
}).then((result) => { | ||
t.equal(result[0].dateEnable.toString(), newDateEnable.toString(), 'Job reanimate dateEnable is valid') | ||
@@ -90,0 +93,0 @@ t.equal(result[0].log.length, 4, 'Job reanimate log is valid') |
@@ -15,4 +15,3 @@ const test = require('tap').test | ||
test(testName, (t) => { | ||
// t.plan(135) | ||
t.plan(142) | ||
t.plan(147) | ||
@@ -69,3 +68,3 @@ // ---------- Test Setup ---------- | ||
terminated: 0, | ||
reanimated: 0, | ||
reanimated: 1, | ||
log: 0, | ||
@@ -211,5 +210,16 @@ updated: 0 | ||
// ---------- Reanimate Job Tests ---------- | ||
t.comment('queue: Reanimate Job') | ||
return qMain.reanimateJob(job.id) | ||
}).then((reanimatedJobs) => { | ||
t.ok(is.array(reanimatedJobs), 'Reanimate job returns an array') | ||
t.ok(is.uuid(reanimatedJobs[0]), 'Reanimate job returns ids') | ||
return qMain.getJob(reanimatedJobs[0]) | ||
}).then((reanimatedJobs2) => { | ||
t.ok(is.array(reanimatedJobs2), 'Get job returns an array') | ||
t.equal(reanimatedJobs2[0].status, enums.status.waiting, 'Reanimated job status is waiting') | ||
// ---------- Remove Job Tests ---------- | ||
t.comment('queue: Remove Job') | ||
return qMain.removeJob(cancelledJobs2[0].id) | ||
return qMain.removeJob(job.id) | ||
}).then((removedCount) => { | ||
@@ -216,0 +226,0 @@ t.ok(is.array(removedCount), 'Remove job returns an array') |
545664
7659