kue icon indicating copy to clipboard operation
kue copied to clipboard

Job on complete event

Open sarincasm opened this issue 7 years ago • 6 comments

When fetching a job like this -

kue.Job.get(someId, (err, job) => {
	job.on('complete', () => { // never called
		debug('on get')
		// do stuff after job is complete
	})
	job.inactive()
})

here this event handler is never called, probably because kue.Job.get doesn't return an object that has that listener. Is there a way to listen to job events when fetching events like this ? or a way to listen to complete event for a particular job (by job id)

This works fine, but doesn't serve the purpose -

const job = queue.create('name', {
	title
})
.delay(1200000)
.attempts(3)
.save(err => {
	if(err)
		return
	// save job.id
})
job.on('complete', () => {
	debug('on create')
})

sarincasm avatar Sep 25 '17 03:09 sarincasm

Did you save() the job before fetch it from kue server? Is yes, let log the (error, job) when you receive response from fetch.

Let try this approach:

let someId
const job = queue.create('name', {title})
.delay(1200000)
.attempts(3)
.save(err => {
  if(err)
    return
  someId = job.id
})

kue.Job.get(someId, (err, job) => {
console.log('error', err)
console.log('job', job)
  job.on('complete', () => { 
	debug('on get')
	// do stuff after job is complete
  })
  job.inactive()
})

CQBinh avatar Nov 03 '17 03:11 CQBinh

hi @CQBinh .. how is your code different ? That is what i have done, but the job.on('complete') listener is never called.

sarincasm avatar Nov 06 '17 09:11 sarincasm

@eelsweb First, I guess that you forget to save() the job after call: queue.create().

Btw: let post your full code with log from kue.Job.get() calling, so I can look deeper.

CQBinh avatar Nov 06 '17 10:11 CQBinh

Does anyone know how to listen for when all jobs in a queue are completed?

expresstechsoftwares avatar Feb 21 '18 11:02 expresstechsoftwares

@expresstechsoftwares https://github.com/Automattic/kue#queue-events

CQBinh avatar Feb 26 '18 02:02 CQBinh

Anyone solve this?

vernk avatar Sep 27 '18 11:09 vernk