rethinkdb-job-queue
Advanced tools
Comparing version 1.0.1 to 1.0.2
'use strict'; | ||
var logger = require('./logger')(module); | ||
var state = Object.freeze({ | ||
docId: '86f6ff5b-0c4e-46ad-9a5f-e90eb19c9b00', | ||
global: 'global', | ||
local: 'local' | ||
}); | ||
var priority = Object.freeze({ | ||
lowest: 60, | ||
low: 50, | ||
normal: 40, | ||
medium: 30, | ||
high: 20, | ||
highest: 10 | ||
}); | ||
var status = Object.freeze({ | ||
// ---------- Queue Status Values ---------- | ||
ready: 'ready', | ||
processing: 'processing', | ||
progress: 'progress', | ||
pausing: 'pausing', | ||
paused: 'paused', | ||
resumed: 'resumed', | ||
removed: 'removed', | ||
idle: 'idle', | ||
reset: 'reset', | ||
error: 'error', | ||
reviewed: 'reviewed', | ||
detached: 'detached', | ||
stopping: 'stopping', | ||
stopped: 'stopped', | ||
dropped: 'dropped', | ||
// ---------- Job Status Values ---------- | ||
created: 'created', // Non-event, initial create job status | ||
added: 'added', // Event only, not a job status | ||
waiting: 'waiting', // Non-event, job status only | ||
active: 'active', | ||
completed: 'completed', | ||
cancelled: 'cancelled', | ||
failed: 'failed', | ||
terminated: 'terminated', | ||
log: 'log', // Event only, not a job status | ||
updated: 'updated' // Event only, not a job status | ||
}); | ||
var options = Object.freeze({ | ||
name: 'rjqJobList', | ||
host: 'localhost', | ||
port: 28015, | ||
db: 'rjqJobQueue', | ||
masterInterval: 310000, // 5 minutes and 10 seconds | ||
priority: 'normal', | ||
timeout: 300000, // 5 minutes | ||
retryMax: 3, | ||
retryDelay: 600000, // 10 minutes | ||
concurrency: 1, | ||
removeFinishedJobs: 15552000000 // 180 days | ||
}); | ||
var index = Object.freeze({ | ||
indexActiveDateEnable: 'indexActiveDateEnable', | ||
indexInactivePriorityDateCreated: 'indexInactivePriorityDateCreated', | ||
indexFinishedDateFinished: 'indexFinishedDateFinished' | ||
}); | ||
var dbResult = Object.freeze({ | ||
deleted: 'deleted', | ||
errors: 'errors', | ||
inserted: 'inserted', | ||
replaced: 'replaced', | ||
skipped: 'skipped', | ||
changes: 'changes', | ||
unchanged: 'unchanged' | ||
}); | ||
var log = Object.freeze({ | ||
information: 'information', | ||
warning: 'warning', | ||
error: 'error' | ||
}); | ||
var message = Object.freeze({ | ||
jobAdded: 'Job added to the queue', | ||
active: 'Job retrieved and active', | ||
completed: 'Job completed successfully', | ||
failed: 'Job processing failed', | ||
cancel: 'Job cancelled by Queue process handler', | ||
seeLogData: 'See the data attached to this log entry', | ||
jobUpdated: 'Job updated. Old values in log data', | ||
jobProgress: 'Job progress updated. Old value in log data', | ||
jobNotAdded: 'Job not added to the queue', | ||
jobAlreadyAdded: 'Job is already in the queue', | ||
jobDataInvalid: 'Job data can not be a function', | ||
jobInvalid: 'Job object is invalid', | ||
processTwice: 'Cannot call queue process twice', | ||
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', | ||
concurrencyInvalid: 'Invalid concurrency value', | ||
cancelCallbackInvalid: 'The onCancel callback is not a function', | ||
globalStateError: 'The global state document change feed is invalid', | ||
noErrorStack: 'The error has no stack detail', | ||
noErrorMessage: 'The error has no message' | ||
}); | ||
@@ -13,102 +114,10 @@ var enums = module.exports = { | ||
state: { | ||
docId: '86f6ff5b-0c4e-46ad-9a5f-e90eb19c9b00', | ||
global: 'global', | ||
local: 'local' | ||
}, | ||
priority: { | ||
lowest: 60, | ||
low: 50, | ||
normal: 40, | ||
medium: 30, | ||
high: 20, | ||
highest: 10 | ||
}, | ||
status: { | ||
// ---------- Queue Status Values ---------- | ||
ready: 'ready', | ||
processing: 'processing', | ||
progress: 'progress', | ||
pausing: 'pausing', | ||
paused: 'paused', | ||
resumed: 'resumed', | ||
removed: 'removed', | ||
idle: 'idle', | ||
reset: 'reset', | ||
error: 'error', | ||
reviewed: 'reviewed', | ||
detached: 'detached', | ||
stopping: 'stopping', | ||
stopped: 'stopped', | ||
dropped: 'dropped', | ||
// ---------- Job Status Values ---------- | ||
created: 'created', // Non-event, initial create job status | ||
added: 'added', // Event only, not a job status | ||
waiting: 'waiting', // Non-event, job status only | ||
active: 'active', | ||
completed: 'completed', | ||
cancelled: 'cancelled', | ||
failed: 'failed', | ||
terminated: 'terminated', | ||
log: 'log', // Event only, not a job status | ||
updated: 'updated' // Event only, not a job status | ||
}, | ||
options: { | ||
name: 'rjqJobList', | ||
host: 'localhost', | ||
port: 28015, | ||
db: 'rjqJobQueue', | ||
masterInterval: 310000, // 5 minutes and 10 seconds | ||
priority: 'normal', | ||
timeout: 300000, // 5 minutes | ||
retryMax: 3, | ||
retryDelay: 600000, // 10 minutes | ||
concurrency: 1, | ||
removeFinishedJobs: 15552000000 // 180 days | ||
}, | ||
index: { | ||
indexActiveDateEnable: 'indexActiveDateEnable', | ||
indexInactivePriorityDateCreated: 'indexInactivePriorityDateCreated', | ||
indexFinishedDateFinished: 'indexFinishedDateFinished' | ||
}, | ||
dbResult: { | ||
deleted: 'deleted', | ||
errors: 'errors', | ||
inserted: 'inserted', | ||
replaced: 'replaced', | ||
skipped: 'skipped', | ||
changes: 'changes', | ||
unchanged: 'unchanged' | ||
}, | ||
log: { | ||
information: 'information', | ||
warning: 'warning', | ||
error: 'error' | ||
}, | ||
message: { | ||
jobAdded: 'Job added to the queue', | ||
active: 'Job retrieved and active', | ||
completed: 'Job completed successfully', | ||
failed: 'Job processing failed', | ||
cancel: 'Job cancelled by Queue process handler', | ||
seeLogData: 'See the data attached to this log entry', | ||
jobUpdated: 'Job updated. Old values in log data', | ||
jobNotAdded: 'Job not added to the queue', | ||
jobAlreadyAdded: 'Job is already in the queue', | ||
jobDataInvalid: 'Job data can not be a function', | ||
jobInvalid: 'Job object is invalid', | ||
processTwice: 'Cannot call queue process twice', | ||
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', | ||
concurrencyInvalid: 'Invalid concurrency value', | ||
cancelCallbackInvalid: 'The onCancel callback is not a function', | ||
globalStateError: 'The global state document change feed is invalid', | ||
noErrorStack: 'The error has no stack detail', | ||
noErrorMessage: 'The error has no message' | ||
} | ||
state: state, | ||
priority: priority, | ||
status: status, | ||
options: options, | ||
index: index, | ||
dbResult: dbResult, | ||
log: log, | ||
message: message | ||
}; |
@@ -7,3 +7,3 @@ 'use strict'; | ||
var enums = require('./enums'); | ||
var jobAddLog = require('./job-add-log'); | ||
var jobLog = require('./job-log'); | ||
var dbResult = require('./db-result'); | ||
@@ -19,3 +19,3 @@ | ||
var log = jobAddLog.createLogObject(job, result, enums.message.completed); | ||
var log = jobLog.createLogObject(job, result, enums.message.completed); | ||
log.duration = duration; | ||
@@ -22,0 +22,0 @@ |
@@ -7,3 +7,3 @@ 'use strict'; | ||
var enums = require('./enums'); | ||
var jobAddLog = require('./job-add-log'); | ||
var jobLog = require('./job-log'); | ||
var dbResult = require('./db-result'); | ||
@@ -32,3 +32,3 @@ var serializeError = require('serialize-error'); | ||
var log = jobAddLog.createLogObject(job, errAsString, enums.message.failed, logType, job.status); | ||
var log = jobLog.createLogObject(job, errAsString, enums.message.failed, logType, job.status); | ||
log.duration = duration; | ||
@@ -35,0 +35,0 @@ log.errorMessage = err && err.message ? err.message : enums.message.noErrorMessage; |
@@ -7,2 +7,3 @@ 'use strict'; | ||
var enums = require('./enums'); | ||
var jobLog = require('./job-log'); | ||
@@ -23,6 +24,11 @@ module.exports = function jobProgress(job, percent) { | ||
return Promise.resolve().then(function () { | ||
return job.q.r.db(job.q.db).table(job.q.name).get(job.id).pluck('progress').run(); | ||
}).then(function (pluck) { | ||
return jobLog.createLogObject(job, pluck.progress, enums.message.jobProgress, enums.log.information); | ||
}).then(function (newLog) { | ||
return job.q.r.db(job.q.db).table(job.q.name).get(job.id).update({ | ||
queueId: job.q.id, | ||
progress: percent, | ||
dateEnable: job.q.r.now().add(job.q.r.row('timeout').div(1000)).add(job.q.r.row('retryDelay').div(1000).mul(job.q.r.row('retryCount'))) | ||
dateEnable: job.q.r.now().add(job.q.r.row('timeout').div(1000)).add(job.q.r.row('retryDelay').div(1000).mul(job.q.r.row('retryCount'))), | ||
log: job.q.r.row('log').append(newLog) | ||
}).run(); | ||
@@ -29,0 +35,0 @@ }).then(function (updateResult) { |
@@ -7,3 +7,3 @@ 'use strict'; | ||
var queueGetJob = require('./queue-get-job'); | ||
var jobAddLog = require('./job-add-log'); | ||
var jobLog = require('./job-log'); | ||
@@ -13,9 +13,8 @@ module.exports = function jobUpdate(job) { | ||
var log = jobAddLog.createLogObject(job, null, enums.message.jobUpdated, enums.log.information); | ||
return Promise.resolve().then(function () { | ||
return queueGetJob(job.q, job.id); | ||
}).then(function (oldJobs) { | ||
log.data = oldJobs[0].getCleanCopy(); | ||
delete log.data.log; | ||
var oldJobCopy = oldJobs[0].getCleanCopy(); | ||
delete oldJobCopy.log; | ||
var log = jobLog.createLogObject(job, oldJobCopy, enums.message.jobUpdated, enums.log.information); | ||
job.log.push(log); | ||
@@ -22,0 +21,0 @@ return job.getCleanCopy(); |
@@ -14,3 +14,3 @@ 'use strict'; | ||
var jobUpdate = require('./job-update'); | ||
var jobAddLog = require('./job-add-log'); | ||
var jobLog = require('./job-log'); | ||
@@ -158,3 +158,3 @@ var Job = function () { | ||
return this.q.ready().then(function () { | ||
return jobAddLog.commitLog(_this3, data, message, type, status); | ||
return jobLog.commitLog(_this3, data, message, type, status); | ||
}).catch(function (err) { | ||
@@ -166,2 +166,7 @@ logger('addLog Error:', err); | ||
} | ||
}, { | ||
key: 'getLastLog', | ||
value: function getLastLog() { | ||
return jobLog.getLastLog(this); | ||
} | ||
}]); | ||
@@ -168,0 +173,0 @@ |
@@ -8,3 +8,3 @@ 'use strict'; | ||
var dbResult = require('./db-result'); | ||
var jobAddLog = require('./job-add-log'); | ||
var jobLog = require('./job-log'); | ||
var jobParse = require('./job-parse'); | ||
@@ -23,3 +23,3 @@ | ||
} | ||
var log = jobAddLog.createLogObject(oneJob, null, enums.message.jobAdded, enums.log.information, enums.status.waiting); | ||
var log = jobLog.createLogObject(oneJob, null, enums.message.jobAdded, enums.log.information, enums.status.waiting); | ||
oneJob.log.push(log); | ||
@@ -26,0 +26,0 @@ return oneJob.getCleanCopy(); |
{ | ||
"name": "rethinkdb-job-queue", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "A persistent job or task queue backed by RethinkDB.", | ||
@@ -57,5 +57,5 @@ "main": "index.js", | ||
"devDependencies": { | ||
"babel-cli": "^6.16.0", | ||
"babel-cli": "^6.18.0", | ||
"babel-preset-latest": "^6.16.0", | ||
"npm-check-updates": "^2.8.5", | ||
"npm-check-updates": "^2.8.6", | ||
"proxyquire": "^1.7.10", | ||
@@ -62,0 +62,0 @@ "standard": "^8.4.0", |
@@ -39,3 +39,3 @@ # Introduction | ||
* Rich job [history log][job-log-url] | ||
* Over 1300 [integration tests][testing-url] | ||
* Over 1400 [integration tests][testing-url] | ||
@@ -63,6 +63,8 @@ [queue-connection-url]: https://github.com/grantcarthew/node-rethinkdb-job-queue/wiki/Queue-Connection | ||
See the [Change Log][rjq-changelog-url] for recent changes. | ||
## Project Status | ||
* This `rethinkdb-job-queue` module is fully functional. | ||
* There are over 1300 integration tests. | ||
* There are over 1400 integration tests. | ||
* Updated to v1.0.0 to support [SemVer](http://semver.org/). | ||
@@ -198,2 +200,10 @@ | ||
## About the Owner | ||
I, Grant Carthew, am a technologist, trainer, and Dad from Queensland, Australia. I work on code in a number of personal projects and when the need arises I build my own packages. | ||
This project exists because there were no functional job queues built on the RethinkDB database. I wanted an alternative to the other job queues on NPM. | ||
Everything I do in open source is done in my own time and as a contribution to the open source community. | ||
## Contributing | ||
@@ -230,2 +240,3 @@ | ||
[rjq-wiki-url]: https://github.com/grantcarthew/node-rethinkdb-job-queue/wiki | ||
[rjq-changelog-url]: https://github.com/grantcarthew/node-rethinkdb-job-queue/wiki/Change-Log | ||
[thinker-image]: https://cdn.rawgit.com/grantcarthew/node-rethinkdb-job-queue/master/thinkerjoblist.png | ||
@@ -232,0 +243,0 @@ [nodemailer-url]: https://www.npmjs.com/package/nodemailer |
const test = require('tape') | ||
const tError = require('./test-error') | ||
const enums = require('../src/enums') | ||
const enums = require('../dist/enums') | ||
@@ -22,3 +22,3 @@ module.exports = function () { | ||
t.equal(Object.keys(enums.log).length, 3, 'Enums log has correct number of keys') | ||
t.equal(Object.keys(enums.message).length, 24, 'Enums message has correct number of keys') | ||
t.equal(Object.keys(enums.message).length, 25, 'Enums message has correct number of keys') | ||
} catch (err) { | ||
@@ -25,0 +25,0 @@ tError(err, module, t) |
@@ -10,2 +10,3 @@ const test = require('tape') | ||
const tOpts = require('./test-options') | ||
const eventHandlers = require('./test-event-handlers') | ||
@@ -15,3 +16,3 @@ module.exports = function () { | ||
test('job-progress', (t) => { | ||
t.plan(23) | ||
t.plan(46) | ||
@@ -23,17 +24,32 @@ const q = new Queue(tOpts.cxn(), tOpts.default()) | ||
job.retryCount = 0 | ||
let oldPercent | ||
let testEvents = false | ||
function progressEventHandler (jobId, percent) { | ||
if (testEvents) { | ||
t.equal(jobId, job.id, `Event: Job progress [${percent}]`) | ||
} | ||
// ---------- Event Handler Setup ---------- | ||
let state = { | ||
enabled: false, | ||
ready: 0, | ||
processing: 0, | ||
progress: 6, | ||
pausing: 0, | ||
paused: 0, | ||
resumed: 0, | ||
removed: 0, | ||
idle: 0, | ||
reset: 0, | ||
error: 0, | ||
reviewed: 0, | ||
detached: 0, | ||
stopping: 0, | ||
stopped: 0, | ||
dropped: 0, | ||
added: 0, | ||
waiting: 0, | ||
active: 0, | ||
completed: 0, | ||
cancelled: 0, | ||
failed: 0, | ||
terminated: 0, | ||
log: 0, | ||
updated: 0 | ||
} | ||
function addEventHandlers () { | ||
testEvents = true | ||
q.on(enums.status.progress, progressEventHandler) | ||
} | ||
function removeEventHandlers () { | ||
testEvents = false | ||
q.removeListener(enums.status.progress, progressEventHandler) | ||
} | ||
@@ -43,3 +59,3 @@ let tempDateEnable = job.dateEnable | ||
t.equal(savedJob[0].id, job.id, 'Job saved successfully') | ||
addEventHandlers() | ||
eventHandlers.add(t, q, state) | ||
savedJob[0].retryCount = 1 | ||
@@ -97,2 +113,3 @@ savedJob[0].status = enums.status.active | ||
t.equal(updatedJob[0].progress, 100, 'Job progress is 100 percent') | ||
t.equal(updatedJob[0].getLastLog().data, 50, 'Job progress log contains old percent') | ||
updatedJob[0].status = enums.status.active | ||
@@ -110,3 +127,5 @@ return jobProgress(updatedJob[0], 101) | ||
removeEventHandlers() | ||
// ---------- Event Summary ---------- | ||
t.comment('job-progress: Event Summary') | ||
eventHandlers.remove(t, q, state) | ||
return q.reset() | ||
@@ -113,0 +132,0 @@ }).then((resetResult) => { |
@@ -19,3 +19,3 @@ const Promise = require('bluebird') | ||
const jobFailed = require('./job-failed.spec') | ||
const jobAddLog = require('./job-add-log.spec') | ||
const jobLog = require('./job-log.spec') | ||
const queue = require('./queue.spec') | ||
@@ -22,0 +22,0 @@ const queueDb = require('./queue-db.spec') |
@@ -19,3 +19,3 @@ const Promise = require('bluebird') | ||
const jobFailed = require('./job-failed.spec') | ||
const jobAddLog = require('./job-add-log.spec') | ||
const jobLog = require('./job-log.spec') | ||
const queue = require('./queue.spec') | ||
@@ -55,3 +55,3 @@ const queueDb = require('./queue-db.spec') | ||
jobProgress(), | ||
jobAddLog(), | ||
jobLog(), | ||
jobUpdate(), | ||
@@ -58,0 +58,0 @@ queueGetJob(), |
6826
255
296195
83