-
Notifications
You must be signed in to change notification settings - Fork 16
Job.addLog
Parameter: data
Object Optional
- Data that will be added to the
log.data
property. - Default: An empty object.
Parameter: message
String Optional
- String that will be added to the
log.message
property. - Default: 'See the data attached to this log entry'
Parameter: type
String Optional
- String that will be added to the
log.type
property. Typicallyinformation
,warning
, orerror
. -
Default:
information
Parameter: status
String Optional
- String that will be added to the
log.status
property. - Default: The job current status.
Returns: Promise
=> true
Example:
job.addLog({ foo: 'bar'},
'Job data changed',
'warning',
'active').catch(err => console.error(err))
During the life cycle of a job the Queue objects will populate job history as log entries. At anytime you can call Queue.getJob or Queue.findJob and examine the Job.log
property.
For any reason at all you may want to add your own log entry to a job in the queue. This is easy to do thanks to the Job.addLog
method on a Job object. Once a log has been added to the job it will exist in the database on the Job.log
property within an Array of log entries.
Note: Job.addLog
will commit the log entry to the queue database at the time you call the method. Ensure you catch any errors.
So you can appreciate what a job log looks like, here is the result of calling Job.getCleanCopy(true)
on a job with some history. This job was taken from the rethinkdb-job-queue
process tests.
{
"dateCreated": Sun Oct 09 2016 22:57:18 GMT+00:00 ,
"dateEnable": Sun Oct 09 2016 22:57:36 GMT+00:00 ,
"dateFinished": Sun Oct 09 2016 22:57:30 GMT+00:00 ,
"dateStarted": Sun Oct 09 2016 22:57:29 GMT+00:00 ,
"id": "c8536c2a-4fc9-42d0-9ee0-3b8f6a876ed4" ,
"log": [
{
"data": null ,
"date": Sun Oct 09 2016 22:57:18 GMT+00:00 ,
"message": "Job added to the queue" ,
"queueId": "WebDev:rjqJobQueueTests:rjqJobQueueTestJobs:1460:d464d60d-1fff-48ce-9a64-3a988b4a3f6b" ,
"retryCount": 0 ,
"status": "waiting" ,
"type": "information"
} ,
{
"date": Sun Oct 09 2016 22:57:18 GMT+00:00 ,
"message": "Job retrieved and active" ,
"queueId": "WebDev:rjqJobQueueTests:rjqJobQueueTestJobs:1460:d464d60d-1fff-48ce-9a64-3a988b4a3f6b" ,
"retryCount": 0 ,
"status": "active" ,
"type": "information"
} ,
{
"data": {
"message": "Job timed out (run time > 1000 ms)" ,
"name": "Error" ,
"stack": "Error: Job timed out (run time > 1000 ms)
at Timeout.timeoutHandler (/home/grant/node-rethinkdb-job-queue/src/queue-process.js:113:17)
at tryOnTimeout (timers.js:232:11)
at Timer.listOnTimeout (timers.js:202:5)"
} ,
"date": Sun Oct 09 2016 22:57:19 GMT+00:00 ,
"duration": 1027 ,
"errorMessage": "Job timed out (run time > 1000 ms)" ,
"errorStack": "Error: Job timed out (run time > 1000 ms)
at Timeout.timeoutHandler (/home/grant/node-rethinkdb-job-queue/src/queue-process.js:113:17)
at tryOnTimeout (timers.js:232:11)
at Timer.listOnTimeout (timers.js:202:5)" ,
"message": "Job processing failed" ,
"queueId": "WebDev:rjqJobQueueTests:rjqJobQueueTestJobs:1460:d464d60d-1fff-48ce-9a64-3a988b4a3f6b" ,
"retryCount": 1 ,
"status": "failed" ,
"type": "warning"
} ,
{
"date": Sun Oct 09 2016 22:57:20 GMT+00:00 ,
"message": "Job retrieved and active" ,
"queueId": "WebDev:rjqJobQueueTests:rjqJobQueueTestJobs:1460:d464d60d-1fff-48ce-9a64-3a988b4a3f6b" ,
"retryCount": 1 ,
"status": "active" ,
"type": "information"
} ,
{
"data": {
"message": "Job timed out (run time > 1000 ms)" ,
"name": "Error" ,
"stack": "Error: Job timed out (run time > 1000 ms)
at Timeout.timeoutHandler (/home/grant/node-rethinkdb-job-queue/src/queue-process.js:113:17)
at tryOnTimeout (timers.js:232:11)
at Timer.listOnTimeout (timers.js:202:5)"
} ,
"date": Sun Oct 09 2016 22:57:21 GMT+00:00 ,
"duration": 1036 ,
"errorMessage": "Job timed out (run time > 1000 ms)" ,
"errorStack": "Error: Job timed out (run time > 1000 ms)
at Timeout.timeoutHandler (/home/grant/node-rethinkdb-job-queue/src/queue-process.js:113:17)
at tryOnTimeout (timers.js:232:11)
at Timer.listOnTimeout (timers.js:202:5)" ,
"message": "Job processing failed" ,
"queueId": "WebDev:rjqJobQueueTests:rjqJobQueueTestJobs:1460:d464d60d-1fff-48ce-9a64-3a988b4a3f6b" ,
"retryCount": 2 ,
"status": "failed" ,
"type": "warning"
} ,
{
"date": Sun Oct 09 2016 22:57:24 GMT+00:00 ,
"message": "Job retrieved and active" ,
"queueId": "WebDev:rjqJobQueueTests:rjqJobQueueTestJobs:1460:d464d60d-1fff-48ce-9a64-3a988b4a3f6b" ,
"retryCount": 2 ,
"status": "active" ,
"type": "information"
} ,
{
"data": {
"message": "Job timed out (run time > 1000 ms)" ,
"name": "Error" ,
"stack": "Error: Job timed out (run time > 1000 ms)
at Timeout.timeoutHandler (/home/grant/node-rethinkdb-job-queue/src/queue-process.js:113:17)
at tryOnTimeout (timers.js:232:11)
at Timer.listOnTimeout (timers.js:202:5)"
} ,
"date": Sun Oct 09 2016 22:57:25 GMT+00:00 ,
"duration": 1074 ,
"errorMessage": "Job timed out (run time > 1000 ms)" ,
"errorStack": "Error: Job timed out (run time > 1000 ms)
at Timeout.timeoutHandler (/home/grant/node-rethinkdb-job-queue/src/queue-process.js:113:17)
at tryOnTimeout (timers.js:232:11)
at Timer.listOnTimeout (timers.js:202:5)" ,
"message": "Job processing failed" ,
"queueId": "WebDev:rjqJobQueueTests:rjqJobQueueTestJobs:1460:d464d60d-1fff-48ce-9a64-3a988b4a3f6b" ,
"retryCount": 3 ,
"status": "failed" ,
"type": "warning"
} ,
{
"date": Sun Oct 09 2016 22:57:29 GMT+00:00 ,
"message": "Job retrieved and active" ,
"queueId": "WebDev:rjqJobQueueTests:rjqJobQueueTestJobs:1460:d464d60d-1fff-48ce-9a64-3a988b4a3f6b" ,
"retryCount": 3 ,
"status": "active" ,
"type": "information"
} ,
{
"data": {
"message": "Job timed out (run time > 1000 ms)" ,
"name": "Error" ,
"stack": "Error: Job timed out (run time > 1000 ms)
at Timeout.timeoutHandler (/home/grant/node-rethinkdb-job-queue/src/queue-process.js:113:17)
at tryOnTimeout (timers.js:232:11)
at Timer.listOnTimeout (timers.js:202:5)"
} ,
"date": Sun Oct 09 2016 22:57:30 GMT+00:00 ,
"duration": 1030 ,
"errorMessage": "Job timed out (run time > 1000 ms)" ,
"errorStack": "Error: Job timed out (run time > 1000 ms)
at Timeout.timeoutHandler (/home/grant/node-rethinkdb-job-queue/src/queue-process.js:113:17)
at tryOnTimeout (timers.js:232:11)
at Timer.listOnTimeout (timers.js:202:5)" ,
"message": "Job processing failed" ,
"queueId": "WebDev:rjqJobQueueTests:rjqJobQueueTestJobs:1460:d464d60d-1fff-48ce-9a64-3a988b4a3f6b" ,
"retryCount": 3 ,
"status": "terminated" ,
"type": "error"
}
] ,
"priority": 40 ,
"progress": 0 ,
"queueId": "WebDev:rjqJobQueueTests:rjqJobQueueTestJobs:1460:d464d60d-1fff-48ce-9a64-3a988b4a3f6b" ,
"retryCount": 3 ,
"retryDelay": 2000 ,
"retryMax": 3 ,
"status": "terminated" ,
"timeout": 1000
}
The following is a complete example of creating a job, adding it to the queue, adding a custom log to the job, and getting the job from the database. This example does not include processing jobs with Queue.process.
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
let job = q.createJob({ content: 'some job data' })
q.addJob(job).then((savedJobs) => {
sJob = savedJobs[0]
return sJob.addLog({ info: 'Something you want to add' }, 'log history message')
}).then(() => {
// The in memory job will have the new log
// No need to call getJob
return q.getJob(job)
}).then((ourJobs) => {
oJob = ourJobs[0]
// oJob.log.length === 2
// One log for being added to the queue and
// one custom log entry.
// oJob.log[1].data.info === 'Something you want to add'
}).catch(err => console.error(err))
- Introduction
- Tutorial
- Queue Constructor
- Queue Connection
- Queue Options
- Queue PubSub
- Queue Master
- Queue Events
- State Document
- Job Processing
- Job Options
- Job Status
- Job Retry
- Job Repeat
- Job Logging
- Job Editing
- Job Schema
- Job Name
- Complex Job
- Delayed Job
- Cancel Job
- Error Handling
- Queue.createJob
- Queue.addJob
- Queue.getJob
- Queue.findJob
- Queue.findJobByName
- Queue.containsJobByName
- Queue.cancelJob
- Queue.reanimateJob
- Queue.removeJob
- Queue.process
- Queue.review
- Queue.summary
- Queue.ready
- Queue.pause
- Queue.resume
- Queue.reset
- Queue.stop
- Queue.drop
- Queue.Job
- Queue.host
- Queue.port
- Queue.db
- Queue.name
- Queue.r
- Queue.id
- Queue.jobOptions [R/W]
- Queue.changeFeed
- Queue.master
- Queue.masterInterval
- Queue.removeFinishedJobs
- Queue.running
- Queue.concurrency [R/W]
- Queue.paused
- Queue.idle
- Event.ready
- Event.added
- Event.updated
- Event.active
- Event.processing
- Event.progress
- Event.log
- Event.pausing
- Event.paused
- Event.resumed
- Event.completed
- Event.cancelled
- Event.failed
- Event.terminated
- Event.reanimated
- Event.removed
- Event.idle
- Event.reset
- Event.error
- Event.reviewed
- Event.detached
- Event.stopping
- Event.stopped
- Event.dropped
- Job.setName
- Job.setPriority
- Job.setTimeout
- Job.setDateEnable
- Job.setRetryMax
- Job.setRetryDelay
- Job.setRepeat
- Job.setRepeatDelay
- Job.updateProgress
- Job.update
- Job.getCleanCopy
- Job.addLog
- Job.getLastLog