rethinkdb-job-queue
Advanced tools
Comparing version 0.3.0 to 0.4.0
# `rethinkdb-job-queue` Change log | ||
## v0.4.0 / 2016-09-30 | ||
* Added `is.log` to the `is` module. | ||
* Added `Job.setPriority`, `Job.setTimeout`, `Job.setRetryMax`, `Job.setRetryDelay`, `setDateEnable`. | ||
* Added string, object, or log arguments to `Job.addLog`. | ||
* Changed `Queue.createJob` API to support data objects, values and options. | ||
## v0.3.0 / 2016-09-28 | ||
@@ -4,0 +11,0 @@ |
@@ -98,2 +98,7 @@ 'use strict'; | ||
idInvalid: 'The job id is invalid', | ||
priorityInvalid: 'The job priority value is invalid', | ||
timeoutInvalid: 'The job timeout value is invalid', | ||
retryMaxIvalid: 'The job retryMax value is invalid', | ||
retryDelayIvalid: 'The job retryDelay value is invalid', | ||
dateEnableIvalid: 'The job dateEnable value is invalid', | ||
dbError: 'RethinkDB returned an error', | ||
@@ -104,4 +109,4 @@ concurrencyInvalid: 'Invalid concurrency value', | ||
noErrorStack: 'The error has no stack detail', | ||
noErrorMessage: 'The error has no messag' | ||
noErrorMessage: 'The error has no message' | ||
} | ||
}; |
@@ -110,2 +110,23 @@ 'use strict'; | ||
function isLog(value) { | ||
logger('isLog', value); | ||
if (!value) { | ||
return false; | ||
} | ||
if (!isDate(value.date)) { | ||
return false; | ||
} | ||
if (!isString(value.queueId)) { | ||
return false; | ||
} | ||
if (!isString(value.type)) { | ||
return false; | ||
} | ||
if (!isString(value.status)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
module.exports.log = isLog; | ||
function isJob(value) { | ||
@@ -112,0 +133,0 @@ logger('isJob', value); |
@@ -6,2 +6,3 @@ 'use strict'; | ||
var enums = require('./enums'); | ||
var is = require('./is'); | ||
var dbResult = require('./db-result'); | ||
@@ -11,2 +12,12 @@ | ||
logger('addLog', log); | ||
var validLog = log; | ||
if (!is.log(log)) { | ||
if (is.string(log)) { | ||
validLog = job.createLog(log); | ||
} | ||
if (is.object(log)) { | ||
validLog = job.createLog(); | ||
validLog.data = log; | ||
} | ||
} | ||
if (job.status === enums.status.created) { | ||
@@ -17,7 +28,7 @@ return Promise.reject(new Error(enums.message.jobNotAdded)); | ||
return job.q.r.db(job.q.db).table(job.q.name).get(job.id).update({ | ||
log: job.q.r.row('log').append(log), | ||
log: job.q.r.row('log').append(validLog), | ||
queueId: job.q.id | ||
}); | ||
}).then(function (updateResult) { | ||
job.log.push(log); | ||
job.log.push(validLog); | ||
logger('Event: log [' + job.id + ']', updateResult); | ||
@@ -24,0 +35,0 @@ job.q.emit(enums.status.log, job.id); |
@@ -17,3 +17,3 @@ 'use strict'; | ||
var Job = function () { | ||
function Job(q, options) { | ||
function Job(q, jobData) { | ||
_classCallCheck(this, Job); | ||
@@ -23,19 +23,13 @@ | ||
logger('queue id', q.id); | ||
logger('options', options); | ||
logger('jobData', jobData); | ||
this.q = q; | ||
// If creating a job from the database, pass the job as options. | ||
// Eg. new Job(queue, jobFromDb) | ||
if (is.job(options)) { | ||
if (is.job(jobData)) { | ||
logger('Creating job from database object'); | ||
Object.assign(this, options); | ||
Object.assign(this, jobData); | ||
this.priority = enums.priorityFromValue(this.priority); | ||
} else { | ||
logger('Creating new job from defaults and options'); | ||
logger('Creating new job from defaults'); | ||
if (!options) { | ||
options = jobOptions(); | ||
} else { | ||
options = jobOptions(options, this); | ||
} | ||
var options = jobOptions(); | ||
var now = new Date(); | ||
@@ -56,2 +50,8 @@ this.id = uuid.v4(); | ||
this.queueId = q.id; | ||
// Conflicting job options will be overwritten. | ||
if (is.object(jobData)) { | ||
Object.assign(this, jobData); | ||
} else { | ||
this.data = jobData; | ||
} | ||
} | ||
@@ -61,2 +61,47 @@ } | ||
_createClass(Job, [{ | ||
key: 'setPriority', | ||
value: function setPriority(newPriority) { | ||
if (Object.keys(enums.priority).includes(newPriority)) { | ||
this.priority = newPriority; | ||
return this; | ||
} | ||
throw new Error(enums.message.priorityInvalid); | ||
} | ||
}, { | ||
key: 'setTimeout', | ||
value: function setTimeout(newTimeout) { | ||
if (is.integer(newTimeout) && newTimeout >= 0) { | ||
this.timeout = newTimeout; | ||
return this; | ||
} | ||
throw new Error(enums.message.timeoutIvalid); | ||
} | ||
}, { | ||
key: 'setRetryMax', | ||
value: function setRetryMax(newRetryMax) { | ||
if (is.integer(newRetryMax) && newRetryMax >= 0) { | ||
this.retryMax = newRetryMax; | ||
return this; | ||
} | ||
throw new Error(enums.message.retryMaxIvalid); | ||
} | ||
}, { | ||
key: 'setRetryDelay', | ||
value: function setRetryDelay(newRetryDelay) { | ||
if (is.integer(newRetryDelay) && newRetryDelay >= 0) { | ||
this.retryDelay = newRetryDelay; | ||
return this; | ||
} | ||
throw new Error(enums.message.retryDelayIvalid); | ||
} | ||
}, { | ||
key: 'setDateEnable', | ||
value: function setDateEnable(newDateEnable) { | ||
if (is.date(newDateEnable)) { | ||
this.dateEnable = newDateEnable; | ||
return this; | ||
} | ||
throw new Error(enums.message.dateEnableIvalid); | ||
} | ||
}, { | ||
key: 'setProgress', | ||
@@ -63,0 +108,0 @@ value: function setProgress(percent) { |
@@ -195,2 +195,4 @@ 'use strict'; | ||
// Returning a Promise so the jobTick is initiated | ||
// after the dbReview process. The Promise can be ignored. | ||
return Promise.resolve().then(function () { | ||
@@ -197,0 +199,0 @@ if (q.master) { |
@@ -65,19 +65,6 @@ 'use strict'; | ||
key: 'createJob', | ||
value: function createJob() { | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? this.jobOptions : arguments[0]; | ||
var quantity = arguments.length <= 1 || arguments[1] === undefined ? 1 : arguments[1]; | ||
logger('createJob', options, quantity); | ||
if (is.integer(options)) { | ||
quantity = options; | ||
options = this.jobOptions; | ||
} | ||
if (quantity > 1) { | ||
var jobs = []; | ||
for (var i = 0; i < quantity; i++) { | ||
jobs.push(new Job(this, options)); | ||
} | ||
return jobs; | ||
} | ||
return new Job(this, options); | ||
value: function createJob(jobData) { | ||
logger('createJob', jobData); | ||
jobData = jobData == null ? this.jobOptions : jobData; | ||
return new Job(this, jobData); | ||
} | ||
@@ -84,0 +71,0 @@ }, { |
{ | ||
"name": "rethinkdb-job-queue", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "A persistent job or task queue backed by RethinkDB.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# Introduction | ||
`rethinkdb-job-queue` is a persistent job or task queue backed by [RethinkDB][rethinkdb-url]. | ||
It has been build as an alternative to using a [Redis][redis-url] backed job queue such as [Kue][kue-url], [Bull][bull-url], or [Bee-Queue][bee-queue-url]. | ||
It has been built as an alternative to using a [Redis][redis-url] backed job queue such as [Kue][kue-url], [Bull][bull-url], or [Bee-Queue][bee-queue-url]. | ||
@@ -18,2 +18,18 @@ [![bitHound Overall Score][bithound-overall-image]][bithound-overall-url] | ||
## Warning: API change from v0.3.0 to v0.4.0 | ||
The `Queue.createJob()` method no longer takes an option object. | ||
Please read the [createJob](https://github.com/grantcarthew/node-rethinkdb-job-queue/wiki/Queue.createJob) document for more detail. | ||
To enable setting custom job options there is now a fluent API containing the following. | ||
* [Job.setPriority](https://github.com/grantcarthew/node-rethinkdb-job-queue/wiki/Job.setPriority) | ||
* [Job.setTimeout](https://github.com/grantcarthew/node-rethinkdb-job-queue/wiki/Job.setTimeout) | ||
* [Job.setRetryMax](https://github.com/grantcarthew/node-rethinkdb-job-queue/wiki/Job.setRetryMax) | ||
* [Job.setRetryDelay](https://github.com/grantcarthew/node-rethinkdb-job-queue/wiki/Job.setRetryDelay) | ||
* [Job.setDateEnable](https://github.com/grantcarthew/node-rethinkdb-job-queue/wiki/Job.setDateEnable) | ||
I am hoping this will be the last major API change before the v1.0.0 bump. | ||
## Features | ||
@@ -26,2 +42,4 @@ | ||
* Global [queue events][queue-events-url] | ||
* Global [job cancellation][job-cancel-url] | ||
* Global [pause queue][queue-pause-url] | ||
* Run [concurrent jobs][queue-concurrency-url] | ||
@@ -33,3 +51,3 @@ * Promise based with minimal callbacks | ||
* [Find jobs in the queue][find-job-url] | ||
* [Global job cancellation][job-cancel-url] | ||
* [Determine job uniqueness][find-job-url] | ||
* [Job timeout][job-timeout-url] | ||
@@ -53,2 +71,3 @@ * [Retrying failed jobs][job-retry-url] | ||
[job-cancel-url]: https://github.com/grantcarthew/node-rethinkdb-job-queue/wiki/Queue.process#failed-job-with-cancel | ||
[queue-pause-url]: https://github.com/grantcarthew/node-rethinkdb-job-queue/wiki/Queue.pause | ||
[job-timeout-url]: https://github.com/grantcarthew/node-rethinkdb-job-queue/wiki/Job-Options#job-timeout-option | ||
@@ -55,0 +74,0 @@ [job-retry-url]: https://github.com/grantcarthew/node-rethinkdb-job-queue/wiki/Job-Retry |
@@ -22,3 +22,3 @@ const test = require('tape') | ||
t.equal(Object.keys(enums.log).length, 3, 'Enums log has correct number of keys') | ||
t.equal(Object.keys(enums.message).length, 16, 'Enums message has correct number of keys') | ||
t.equal(Object.keys(enums.message).length, 21, 'Enums message has correct number of keys') | ||
} catch (err) { | ||
@@ -25,0 +25,0 @@ tError(err, module, t) |
@@ -8,3 +8,3 @@ const test = require('tape') | ||
test('is', (t) => { | ||
t.plan(57) | ||
t.plan(62) | ||
@@ -22,2 +22,8 @@ const ms = 5000 | ||
} | ||
const log = { | ||
date: new Date, | ||
queueId: 'queue id string', | ||
type: 'type string', | ||
status: 'status string' | ||
} | ||
@@ -97,3 +103,15 @@ t.ok(is.object({}), 'Is object true with object') | ||
t.ok(is.dateBetween(tDate, earlyDate, laterDate), 'Is dateBetween true when between dates') | ||
t.ok(is.log(log), 'Is log true with mock log') | ||
log.date = 'not a date' | ||
t.notOk(is.log(log), 'Is log false with invalid date') | ||
log.date = new Date() | ||
delete log.queueId | ||
t.notOk(is.log(log), 'Is log false with no queueId') | ||
log.queueId = 'queue id string' | ||
delete log.type | ||
t.notOk(is.log(log), 'Is log false with no type') | ||
log.type = 'type string' | ||
delete log.status | ||
t.notOk(is.log(log), 'Is log false with no status`') | ||
}) | ||
} |
@@ -14,9 +14,10 @@ const test = require('tape') | ||
test('job-add-log', (t) => { | ||
t.plan(24) | ||
t.plan(47) | ||
const q = new Queue(tOpts.cxn(), tOpts.default()) | ||
let job = q.createJob() | ||
job.data = tData | ||
job.detail = tData | ||
let testLog | ||
let extra = 'extra data' | ||
let logObject = { foo: 'bar' } | ||
@@ -46,3 +47,3 @@ let testEvents = false | ||
testLog = job.createLog(tData) | ||
testLog.data = tData | ||
testLog.detail = tData | ||
@@ -63,3 +64,3 @@ // ---------- Add First Log Tests ---------- | ||
t.equal(jobWithLog1[0].log[1].message, tData, 'Log 1 message is valid') | ||
t.equal(jobWithLog1[0].log[1].data, tData, 'Log 1 data is valid') | ||
t.equal(jobWithLog1[0].log[1].detail, tData, 'Log 1 detail is valid') | ||
testLog.extra = extra | ||
@@ -81,4 +82,40 @@ | ||
t.equal(jobWithLog2[0].log[2].message, tData, 'Log 2 message is valid') | ||
t.equal(jobWithLog2[0].log[2].data, tData, 'Log 2 data is valid') | ||
t.equal(jobWithLog2[0].log[2].extra, extra, 'Log 2 extra data is valid') | ||
t.equal(jobWithLog2[0].log[2].detail, tData, 'Log 2 detail is valid') | ||
t.equal(jobWithLog2[0].log[2].extra, extra, 'Log 2 extra is valid') | ||
// ---------- Add String Log Tests ---------- | ||
t.comment('job-add-log: Add String Log') | ||
return jobAddLog(job, extra) | ||
}).then((updateResult3) => { | ||
t.equal(updateResult3, 1, 'Log 3 added to job successfully') | ||
return q.getJob(job.id) | ||
}).then((jobWithLog3) => { | ||
t.equal(jobWithLog3[0].log.length, 4, 'Log 3 exists on retrieved job') | ||
t.ok(is.date(jobWithLog3[0].log[3].date), 'Log 3 date is a date') | ||
t.equal(jobWithLog3[0].log[3].queueId, q.id, 'Log 3 queueId is valid') | ||
t.equal(jobWithLog3[0].log[3].type, enums.log.information, 'Log 3 type is information') | ||
t.equal(jobWithLog3[0].log[3].status, enums.status.waiting, 'Log 3 status is added') | ||
t.ok(jobWithLog3[0].log[3].retryCount >= 0, 'Log retryCount is valid') | ||
t.equal(jobWithLog3[0].log[3].message, extra, 'Log 3 message is valid') | ||
t.notEqual(jobWithLog3[0].log[3].detail, tData, 'Log 3 detail is valid') | ||
t.notEqual(jobWithLog3[0].log[3].extra, extra, 'Log 3 extra is valid') | ||
// ---------- Add Object Log Tests ---------- | ||
t.comment('job-add-log: Add Object Log') | ||
return jobAddLog(job, logObject) | ||
}).then((updateResult4) => { | ||
t.equal(updateResult4, 1, 'Log 4 added to job successfully') | ||
return q.getJob(job.id) | ||
}).then((jobWithLog4) => { | ||
t.equal(jobWithLog4[0].log.length, 5, 'Log 4 exists on retrieved job') | ||
t.ok(is.date(jobWithLog4[0].log[4].date), 'Log 4 date is a date') | ||
t.equal(jobWithLog4[0].log[4].queueId, q.id, 'Log 4 queueId is valid') | ||
t.equal(jobWithLog4[0].log[4].type, enums.log.information, 'Log 4 type is information') | ||
t.equal(jobWithLog4[0].log[4].status, enums.status.waiting, 'Log 4 status is added') | ||
t.ok(jobWithLog4[0].log[4].retryCount >= 0, 'Log retryCount is valid') | ||
t.notEqual(jobWithLog4[0].log[4].message, tData, 'Log 4 message is valid') | ||
t.notEqual(jobWithLog4[0].log[4].detail, tData, 'Log 4 detail is valid') | ||
t.notEqual(jobWithLog4[0].log[4].extra, extra, 'Log 4 extra is valid') | ||
t.equal(jobWithLog4[0].log[4].data.foo, 'bar', 'Log 4 data object is valid') | ||
return q.reset() | ||
@@ -85,0 +122,0 @@ }).then((resetResult) => { |
@@ -14,3 +14,3 @@ const test = require('tape') | ||
test('job', (t) => { | ||
t.plan(76) | ||
t.plan(92) | ||
@@ -80,2 +80,21 @@ const q = new Queue(tOpts.cxn(), tOpts.default()) | ||
// ---------- Change Options Tests ---------- | ||
t.comment('job: Change Options') | ||
t.throws(() => { newJob.setPriority('not valid') }, 'Job setPriority thows if invalid') | ||
newJob.setPriority('highest') | ||
t.equal(newJob.priority, 'highest', 'Job setPriority successfully changed value') | ||
t.throws(() => { newJob.setTimeout('not valid') }, 'Job setTimeout thows if invalid') | ||
newJob.setTimeout(100) | ||
t.equal(newJob.timeout, 100, 'Job setTimeout successfully changed value') | ||
t.throws(() => { newJob.setRetryMax('not valid') }, 'Job setRetryMax thows if invalid') | ||
newJob.setRetryMax(100) | ||
t.equal(newJob.retryMax, 100, 'Job setRetryMax successfully changed value') | ||
t.throws(() => { newJob.setRetryDelay('not valid') }, 'Job setRetryDelay thows if invalid') | ||
newJob.setRetryDelay(100) | ||
t.equal(newJob.retryDelay, 100, 'Job setRetryDelay successfully changed value') | ||
t.throws(() => { newJob.setDateEnable('not valid') }, 'Job setDateEnable thows if invalid') | ||
const testDate = new Date() | ||
newJob.setDateEnable(testDate) | ||
t.equal(newJob.dateEnable, testDate, 'Job setDateEnable successfully changed value') | ||
// ---------- Clean Job Tests ---------- | ||
@@ -100,3 +119,3 @@ t.comment('job: Clean Job') | ||
cleanJob = newJob.getCleanCopy(true) | ||
t.equal(cleanJob.priority, 'normal', 'Clean job priorityAsString priority is normal') | ||
t.equal(cleanJob.priority, newJob.priority, 'Clean job priorityAsString priority is normal') | ||
@@ -126,3 +145,3 @@ // ---------- Create Log Tests ---------- | ||
// ---------- New Job From Data ---------- | ||
t.comment('job: New Job from Data') | ||
t.comment('job: New Job from Job Data') | ||
return new Job(q, jobCopy) | ||
@@ -133,3 +152,3 @@ }).then((newJobFromData) => { | ||
t.equal(newJobFromData.data, savedJob.data, 'New job from data job data is valid') | ||
t.equal(newJobFromData.priority, savedJob.priority, 'New job from data priority is valid') | ||
t.equal(newJobFromData.priority, 'normal', 'New job from data priority is valid') | ||
t.equal(newJobFromData.timeout, savedJob.timeout, 'New job from data timeout is valid') | ||
@@ -146,2 +165,16 @@ t.equal(newJobFromData.retryDelay, savedJob.retryDelay, 'New job from data retryDelay is valid') | ||
// ---------- New Jobs with Data and Options ---------- | ||
t.comment('job: New Job with Data and Options') | ||
let custJob = new Job(q, { foo: 'bar' }) | ||
t.equal(custJob.foo, 'bar', 'New job with object data created successfully') | ||
custJob = new Job(q, 'bar') | ||
t.equal(custJob.data, 'bar', 'New job with string data created successfully') | ||
custJob = new Job(q, 1234) | ||
t.equal(custJob.data, 1234, 'New job with number data created successfully') | ||
custJob = new Job(q, true) | ||
t.ok(is.true(custJob.data), 'New job with boolean data created successfully') | ||
custJob = new Job(q, { object: { foo: 'bar' }, priority: 'high' }) | ||
t.equal(custJob.object.foo, 'bar', 'New job with child object data created successfully') | ||
t.equal(custJob.priority, 'high', 'New job with new priority created successfully') | ||
// ---------- Add Job Log ---------- | ||
@@ -148,0 +181,0 @@ t.comment('job: Add Job Log') |
@@ -42,3 +42,6 @@ const test = require('tape') | ||
const jobsToCreate = 5 | ||
let jobs = q.createJob(jobsToCreate) | ||
let jobs = [] | ||
for (let i = 0; i < jobsToCreate; i++) { | ||
jobs.push(q.createJob()) | ||
} | ||
return q.reset().then((resetResult) => { | ||
@@ -81,3 +84,6 @@ t.ok(is.integer(resetResult), 'Queue reset') | ||
t.comment('queue-cancel-job: Cancel Multiple Jobs with Remove') | ||
jobs = q.createJob(jobsToCreate) | ||
jobs = [] | ||
for (let i = 0; i < jobsToCreate; i++) { | ||
jobs.push(q.createJob()) | ||
} | ||
q._removeFinishedJobs = true | ||
@@ -84,0 +90,0 @@ return q.addJob(jobs) |
@@ -149,5 +149,7 @@ const test = require('tape') | ||
function idleEventHandler (queueId) { | ||
idleEventCount++ | ||
if (testEvents) { | ||
t.ok(is.string(queueId), `Event: idle [${idleEventCount} of ${idleEventTotal}] [${queueId}]`) | ||
if (idleEventCount < 1) { | ||
idleEventCount++ | ||
if (testEvents) { | ||
t.ok(is.string(queueId), `Event: idle [${idleEventCount} of ${idleEventTotal}] [${queueId}]`) | ||
} | ||
} | ||
@@ -154,0 +156,0 @@ } |
@@ -27,21 +27,21 @@ const test = require('tape') | ||
const jobLowest = q.createJob({priority: 'lowest'}) | ||
const jobLowest = q.createJob().setPriority('lowest') | ||
jobLowest.status = enums.status.waiting | ||
jobLowest.data = 'Lowest' | ||
const jobLow = q.createJob({priority: 'low'}) | ||
const jobLow = q.createJob().setPriority('low') | ||
jobLow.status = enums.status.waiting | ||
jobLow.data = 'Low' | ||
const jobNormal = q.createJob({priority: 'normal'}) | ||
const jobNormal = q.createJob().setPriority('normal') | ||
jobNormal.status = enums.status.waiting | ||
jobNormal.data = 'Normal' | ||
const jobMedium = q.createJob({priority: 'medium'}) | ||
const jobMedium = q.createJob().setPriority('medium') | ||
jobMedium.status = enums.status.waiting | ||
jobMedium.data = 'Medium' | ||
const jobHigh = q.createJob({priority: 'high'}) | ||
const jobHigh = q.createJob().setPriority('high') | ||
jobHigh.status = enums.status.waiting | ||
jobHigh.data = 'High' | ||
const jobHighest = q.createJob({priority: 'highest'}) | ||
const jobHighest = q.createJob().setPriority('highest') | ||
jobHighest.status = enums.status.waiting | ||
jobHighest.data = 'Highest' | ||
const jobFailed = q.createJob({priority: 'highest'}) | ||
const jobFailed = q.createJob().setPriority('highest') | ||
jobFailed.status = enums.status.failed | ||
@@ -51,12 +51,12 @@ jobFailed.data = 'Failed' | ||
jobFailed.dateCreated = datetime.add.sec(new Date(), -100) | ||
const jobActive = q.createJob({priority: 'normal'}) | ||
const jobActive = q.createJob().setPriority('normal') | ||
jobActive.status = enums.status.active | ||
jobActive.data = 'Active' | ||
const jobCompleted = q.createJob({priority: 'normal'}) | ||
const jobCompleted = q.createJob().setPriority('normal') | ||
jobCompleted.status = enums.status.completed | ||
jobCompleted.data = 'Completed' | ||
const jobCancelled = q.createJob({priority: 'normal'}) | ||
const jobCancelled = q.createJob().setPriority('normal') | ||
jobCancelled.status = enums.status.cancelled | ||
jobCancelled.data = 'Cancelled' | ||
const jobTerminated = q.createJob({priority: 'normal'}) | ||
const jobTerminated = q.createJob().setPriority('normal') | ||
jobTerminated.status = enums.status.terminated | ||
@@ -210,5 +210,5 @@ jobTerminated.data = 'Terminated' | ||
t.comment('queue-get-next-job: dateEnable Values') | ||
retryJobs = q.createJob(2).map(j => j) | ||
retryJobs[0].dateEnable = datetime.add.sec(new Date(), 100) | ||
retryJobs[1].dateEnable = datetime.add.sec(new Date(), -100) | ||
retryJobs = new Array(2) | ||
retryJobs[0] = q.createJob().setDateEnable(datetime.add.sec(new Date(), 100)) | ||
retryJobs[1] = q.createJob().setDateEnable(datetime.add.sec(new Date(), -100)) | ||
return q.addJob(retryJobs) | ||
@@ -224,11 +224,11 @@ }).then((retrySavedJobs) => { | ||
t.comment('queue-get-next-job: dateEnable with retryCount') | ||
retryJobs = q.createJob(4).map(j => j) | ||
retryJobs = new Array(4) | ||
retryJobs[0] = q.createJob().setDateEnable(datetime.add.sec(new Date(), -100)) | ||
retryJobs[0].retryCount = 0 | ||
retryJobs[0].dateEnable = datetime.add.sec(new Date(), -100) | ||
retryJobs[1] = q.createJob().setDateEnable(datetime.add.sec(new Date(), -200)) | ||
retryJobs[1].retryCount = 1 | ||
retryJobs[1].dateEnable = datetime.add.sec(new Date(), -200) | ||
retryJobs[2] = q.createJob().setDateEnable(datetime.add.sec(new Date(), -300)) | ||
retryJobs[2].retryCount = 2 | ||
retryJobs[2].dateEnable = datetime.add.sec(new Date(), -300) | ||
retryJobs[3] = q.createJob().setDateEnable(datetime.add.sec(new Date(), -400)) | ||
retryJobs[3].retryCount = 3 | ||
retryJobs[3].dateEnable = datetime.add.sec(new Date(), -400) | ||
return q.addJob(retryJobs) | ||
@@ -235,0 +235,0 @@ }).then((retrySavedJobs) => { |
@@ -91,5 +91,7 @@ const test = require('tape') | ||
function idleEventHandler (qid) { | ||
if (testEvents) { | ||
idleEventCount++ | ||
t.pass(`Event: idle [${idleEventCount} of ${idleEventTotal}] [${qid}]`) | ||
if (idleEventCount < 12) { | ||
if (testEvents) { | ||
idleEventCount++ | ||
t.pass(`Event: idle [${idleEventCount} of ${idleEventTotal}] [${qid}]`) | ||
} | ||
} | ||
@@ -192,3 +194,6 @@ } | ||
// ---------- Test Setup ---------- | ||
jobs = q.createJob(noOfJobsToCreate).map(j => j) | ||
jobs = [] | ||
for (let i = 0; i < noOfJobsToCreate; i++) { | ||
jobs.push(q.createJob()) | ||
} | ||
return q.reset().then((resetResult) => { | ||
@@ -230,3 +235,6 @@ t.ok(is.integer(resetResult), 'Queue reset') | ||
t.comment('queue-process: Process Restart on Job Add') | ||
jobs = q.createJob(noOfJobsToCreate).map(j => j) | ||
jobs = [] | ||
for (let i = 0; i < noOfJobsToCreate; i++) { | ||
jobs.push(q.createJob()) | ||
} | ||
q._concurrency = 10 | ||
@@ -244,3 +252,6 @@ return q.addJob(jobs) | ||
t.comment('queue-process: Process Restart') | ||
jobs = q.createJob(noOfJobsToCreate).map(j => j) | ||
jobs = [] | ||
for (let i = 0; i < noOfJobsToCreate; i++) { | ||
jobs.push(q.createJob()) | ||
} | ||
return q.addJob(jobs) | ||
@@ -247,0 +258,0 @@ }).then((savedJobs) => { |
@@ -16,3 +16,6 @@ const test = require('tape') | ||
const q = new Queue(tOpts.cxn(), tOpts.default()) | ||
let jobs = q.createJob(3) | ||
let jobs = [] | ||
for (let i = 0; i < 3; i++) { | ||
jobs.push(q.createJob()) | ||
} | ||
@@ -49,3 +52,6 @@ let testEvents = false | ||
t.equal(getResult.length, 0, 'Jobs no longer in database') | ||
let jobs = q.createJob(3).map(j => j) | ||
let jobs = [] | ||
for (let i = 0; i < 3; i++) { | ||
jobs.push(q.createJob()) | ||
} | ||
return q.addJob(jobs) | ||
@@ -52,0 +58,0 @@ }).then((savedAgain) => { |
@@ -17,3 +17,6 @@ const test = require('tape') | ||
const q = new Queue(tOpts.cxn(), tOpts.default()) | ||
const jobs = q.createJob(7).map(j => j) | ||
let jobs = [] | ||
for (let i = 0; i < 7; i++) { | ||
jobs.push(q.createJob()) | ||
} | ||
jobs[0].status = enums.status.waiting | ||
@@ -20,0 +23,0 @@ jobs[1].status = enums.status.active |
@@ -163,5 +163,7 @@ const test = require('tape') | ||
function idleEventHandler (queueId) { | ||
idleEventCount++ | ||
if (testEvents) { | ||
t.ok(is.string(queueId), `Event: idle [${idleEventCount} of ${idleEventTotal}] [${queueId}]`) | ||
if (idleEventCount < 4) { | ||
idleEventCount++ | ||
if (testEvents) { | ||
t.ok(is.string(queueId), `Event: idle [${idleEventCount} of ${idleEventTotal}] [${queueId}]`) | ||
} | ||
} | ||
@@ -339,3 +341,3 @@ } | ||
} | ||
job = q.createJob(customJobOptions) | ||
job = q.createJob().setPriority('low').setTimeout(400).setRetryMax(2).setRetryDelay(900) | ||
t.ok(is.job(job), 'Queue createJob created a job object') | ||
@@ -342,0 +344,0 @@ t.equal(job.priority, customJobOptions.priority, 'Queue created job with custom priority') |
@@ -12,3 +12,3 @@ // const Promise = require('bluebird') | ||
// const dbReview = require('./db-review.spec') | ||
// const job = require('./job.spec') | ||
const job = require('./job.spec') | ||
// const jobOptions = require('./job-options.spec') | ||
@@ -19,3 +19,3 @@ // const jobParse = require('./job-parse.spec') | ||
// const jobUpdate = require('./job-update.spec') | ||
const jobFailed = require('./job-failed.spec') | ||
// const jobFailed = require('./job-failed.spec') | ||
// const jobAddLog = require('./job-add-log.spec') | ||
@@ -41,3 +41,3 @@ // const queue = require('./queue.spec') | ||
}).then(() => { | ||
return jobFailed() | ||
return job() | ||
}) |
288193
6501
267