-
Notifications
You must be signed in to change notification settings - Fork 16
Job.addLog
Parameter: log Object
- A
logobject created by calling Job.createLog.
Returns: Promise => Number
- The number represents the number of log entries updated.
During the life cycle of a job the Queue objects will populate job history as log entries. These log entries are stored on the Job.log property. At anytime you can call Queue.getJob and examine the logs.
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 both the Job.createLog and the Job.addLog methods 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.
Here is what a job with log history looks like. This job was taken from the rethinkdb-job-queue process tests.
{ dateCreated: 2016-08-17T03:44:30.634Z,
dateFinished: 2016-08-17T03:44:42.123Z,
dateRetry: 2016-08-17T03:44:48.086Z,
dateStarted: 2016-08-17T03:44:41.086Z,
id: '0e4a717c-84b1-43f3-98dd-2e670ebc28f9',
log:
[ { date: 2016-08-17T03:44:30.634Z,
message: 'Job added to the queue',
queueId: 'WebDev:rjqJobQueueTests:rjqJobQueueTestJobs:7615:baad3b28-80c9-48ba-a800-73a2ae3a89a2',
retryCount: 0,
status: 'added',
type: 'information' },
{ date: 2016-08-17T03:44:30.672Z,
message: 'Job retrieved and active',
queueId: 'WebDev:rjqJobQueueTests:rjqJobQueueTestJobs:7615:baad3b28-80c9-48ba-a800-73a2ae3a89a2',
retryCount: 0,
status: 'active',
type: 'information' },
{ date: 2016-08-17T03:44:31.728Z,
duration: 1056,
message: 'Job timed out (run time > 1 sec)',
queueId: 'WebDev:rjqJobQueueTests:rjqJobQueueTestJobs:7615:baad3b28-80c9-48ba-a800-73a2ae3a89a2',
retryCount: 1,
status: 'failed',
type: 'warning' },
{ date: 2016-08-17T03:44:31.746Z,
message: 'Job retrieved and active',
queueId: 'WebDev:rjqJobQueueTests:rjqJobQueueTestJobs:7615:baad3b28-80c9-48ba-a800-73a2ae3a89a2',
retryCount: 1,
status: 'active',
type: 'information' },
{ date: 2016-08-17T03:44:32.765Z,
duration: 1018,
message: 'Job timed out (run time > 1 sec)',
queueId: 'WebDev:rjqJobQueueTests:rjqJobQueueTestJobs:7615:baad3b28-80c9-48ba-a800-73a2ae3a89a2',
retryCount: 2,
status: 'failed',
type: 'warning' },
{ date: 2016-08-17T03:44:35.883Z,
message: 'Job retrieved and active',
queueId: 'WebDev:rjqJobQueueTests:rjqJobQueueTestJobs:7615:baad3b28-80c9-48ba-a800-73a2ae3a89a2',
retryCount: 2,
status: 'active',
type: 'information' },
{ date: 2016-08-17T03:44:36.904Z,
duration: 1021,
message: 'Job timed out (run time > 1 sec)',
queueId: 'WebDev:rjqJobQueueTests:rjqJobQueueTestJobs:7615:baad3b28-80c9-48ba-a800-73a2ae3a89a2',
retryCount: 3,
status: 'failed',
type: 'warning' },
{ date: 2016-08-17T03:44:41.086Z,
message: 'Job retrieved and active',
queueId: 'WebDev:rjqJobQueueTests:rjqJobQueueTestJobs:7615:baad3b28-80c9-48ba-a800-73a2ae3a89a2',
retryCount: 3,
status: 'active',
type: 'information' },
{ date: 2016-08-17T03:44:42.123Z,
duration: 1037,
message: 'Job timed out (run time > 1 sec)',
queueId: 'WebDev:rjqJobQueueTests:rjqJobQueueTestJobs:7615:baad3b28-80c9-48ba-a800-73a2ae3a89a2',
retryCount: 3,
status: 'terminated',
type: 'error' } ],
payload: 'The quick brown fox jumped over the lazy dog',
priority: 'normal',
progress: 0,
queueId: 'WebDev:rjqJobQueueTests:rjqJobQueueTestJobs:7615:baad3b28-80c9-48ba-a800-73a2ae3a89a2',
retryCount: 3,
retryDelay: 2,
retryMax: 3,
status: 'terminated',
timeout: 1 }The following is a complete example of creating a job, adding it to the queue, creating a log, adding the log to the job. This example does not include processing jobs with Queue.process.
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
let job = q.createJob()
job.data = 'some job data'
q.addJob(job).then((savedJobs) => {
sJob = savedJobs[0]
const newLog = sJob.createLog('log history message')
newLog.extraInformation = 'Something you want to add'
return sJob.addLog(newLog)
}).then((result) => {
// result === 1
}).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