Kue: Marking a specific job id as completed

Created on 10 Nov 2015  路  5Comments  路  Source: Automattic/kue

Can someone please help with marking a specific job id as completed.

The way my server app works is that its receiving some images from a mobile app, its doing some processing on that image and then it adds the details of the final image and some other details in a Kue job.

Then i need to send all the jobs to another client trough a socket connection that will then pick the first one in the queue, lets say display that image in the browser and then sends a socket event back to the server saying that the image from the jobID X has been shown, then the jobID X needs to be marked as completed, thus being removed from the queue (from the active elements).

So how do i mark a specific ID as completed?

Thank you so much.

Alex

Discussion Feature Question

Most helpful comment

I had a similar problem where I needed to stop an active job from an external script if a new job for the same object was emitted.

To solve my problem, I simply used a global variable so I could access the appropriate 'done()' function from anywhere.

Quick example :

//From Inside the job
function processJob(job, done) {
  //Store the job's done function in a global variable so we can access it from elsewhere.
  _exitActivJob = function() {
    done();
  };
}
//From outside the job
_exitActivJob();

Might not be the ultimate solution but it's simple and effective.

All 5 comments

I found out that i can get the details of a specific job like this, i still cannot figure out how to mark a specific job as completed based on its ID or based on a specific data field from within the jobs data.

Any help would be greatly appreciated.

kue.Job.get(id, function (err, job) {
    var job_progress = job._progress;
    var job_state = job._state
}

Thank you.

the only way to complete a job is calling the done handler passed to your .process, so you currently can not complete a job in another process and you should provide a mediation between your processes to let your original node.js process to call the done callback.

That sounds a bit complicated.

In the end isn't it just a value change of the element in the list?

I had a crack at Bull JS and seems they have something like this: Queue.getJob(id).moveToCompleted()

Any plans of having such a feature in Kue?

Thank you.

Alex

yes we can expose even a REST api to change job state... May be in Kue 1.0!

I had a similar problem where I needed to stop an active job from an external script if a new job for the same object was emitted.

To solve my problem, I simply used a global variable so I could access the appropriate 'done()' function from anywhere.

Quick example :

//From Inside the job
function processJob(job, done) {
  //Store the job's done function in a global variable so we can access it from elsewhere.
  _exitActivJob = function() {
    done();
  };
}
//From outside the job
_exitActivJob();

Might not be the ultimate solution but it's simple and effective.

Was this page helpful?
0 / 5 - 0 ratings