Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

job remove event not triggered #942

Closed
nallown opened this issue Sep 2, 2016 · 11 comments
Closed

job remove event not triggered #942

nallown opened this issue Sep 2, 2016 · 11 comments
Labels

Comments

@nallown
Copy link

nallown commented Sep 2, 2016

I'm trying to kill the child_process associated with the job when the job gets removed from the UI but the remove event isn't getting triggered.

This is what I'm trying to get to work:

const kue = require('kue');
const queue = kue.createQueue();

const spawn = require('child_process').spawn;

queue.process('transcode', 2, function(job, done) {
  const task = spawn(...);

  job.on('remove', function() {
    task.kill('SIGINT');
  });
})

But the remove event isn't getting triggered.

@nallown
Copy link
Author

nallown commented Sep 22, 2016

Any update on this? Is this project still getting maintained?

@behrad
Copy link
Collaborator

behrad commented Oct 21, 2016

job#remove event is triggered on the producer side, not on the worker side!

@nallown
Copy link
Author

nallown commented Oct 22, 2016

Is there a way to check whether the job has been removed from the workers side?

@behrad
Copy link
Collaborator

behrad commented Oct 22, 2016

Job will be out of worker's hand, when you call done.
What do you want to accomplish?

@nallown
Copy link
Author

nallown commented Oct 23, 2016

I'm trying to kill the spawned encoding job through the web UI so you can cancel the encoding job when its running.

@behrad
Copy link
Collaborator

behrad commented Oct 23, 2016

you'd better use gracefulShutdown for this purpose

@nallown
Copy link
Author

nallown commented Oct 23, 2016

I've had a look at the gracefulShutdown and it's not what I'm looking for. It's not the queue that I wish to shutdown its the encoding task. So when you close out a queue job then it would stop the encoding process for that job.

So when the job is removed through the web UI I want to kill the spawned encoding task that belongs to the job.

@behrad
Copy link
Collaborator

behrad commented Oct 23, 2016

why you don't simply call done(new Error('task aborted')) inside worker on your event trigger.

@nallown
Copy link
Author

nallown commented Oct 23, 2016

So something like this? Check out the comments.

worker

const kue = require('kue');
const queue = kue.createQueue();

const spawn = require('child_process').spawn;

queue.process('transcode', 2, function(job, done) {
  const task = spawn(...);

  // kill encoding task on error (triggered when removed through the producer)
  job.on('error', function(error) {
    task.kill('SIGINT');
  });
});

producer

const kue = require('kue');
const queue = kue.createQueue();

const job = queue.create('encoding', {
    title: 'encoding file...',
    source: 'video.mkv',
});

job.on('remove', function() {
  // call done
  job.done(new Error('task aborted'));
});

@behrad
Copy link
Collaborator

behrad commented Oct 23, 2016

No!
Don't remove the job, simply fail it when you have to!
Something may be like this:

var currentJob, doneContext;
queue.process('transcode', 2, function(job, done) {
  currentJob = job;
  doneContext = done;
});

app.on('myTaskKillEvent', function(){
  if( currentJob && doneContext) {
    doneContext(new Error('task aborted'));
  }
});

@nallown
Copy link
Author

nallown commented Oct 23, 2016

Aah right but I'm trying to have this work with the web UI. So you can somehow abort the encoding task through the web UI.

Do you know of a nice way that I can abort the encoding task through the web UI?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants