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

Queue with active job shutdown problem #406

Closed
slyder opened this issue Sep 11, 2014 · 7 comments
Closed

Queue with active job shutdown problem #406

slyder opened this issue Sep 11, 2014 · 7 comments
Labels

Comments

@slyder
Copy link

slyder commented Sep 11, 2014

Behrad, hello, i have next common situation:

var jobReciever = new JobReciever({
redis: config.redis,
jobName: 'job_name',
});

contstructor just connects to redis and creates Kue queue assigned to this.job , then i have next code:

jobReciever.jobs.process('job_name', function(job, done) {
console.log(job.data);
jobReciever.jobs.shutdown(function(err) {
console.log('closing, error: ', err);
}, 3000);
});

and after that node does not close aplication process, so i have to press CTRL+C to stop application.

I see what you have process.exit(0) in shutdown callback, but i need to have other code after queue.shutdown.... is there any way make queue.shutdown while current job is active?

@behrad
Copy link
Collaborator

behrad commented Sep 11, 2014

which kue version are you using?
This is fixed in the latest (0.8.6) kue version when disableSearch: true

@slyder
Copy link
Author

slyder commented Sep 11, 2014

i have kue@0.8.6, but i didn`t have disableSearch: true in queue options
i've added it:

this.jobs = Kue.createQueue({
    redis: {
        port: options.redis.port, 
        host: options.redis.host, 
        auth: options.redis.pass
    },
    disableSearch: true,
});

but it doesn`t help, still have infinite project run
if you need i could make separate file with example

@behrad
Copy link
Collaborator

behrad commented Sep 11, 2014

I'd tested that, send me your code.

@slyder
Copy link
Author

slyder commented Sep 11, 2014

hi, there are the files code:

kue_test1.js:

var config = require('./config');

var Kue = require('kue');

var jobs = Kue.createQueue({
    redis: {
        port: config.redis.port, 
        host: config.redis.host, 
        auth: config.redis.pass
    },
    disableSearch: true,
});

jobs.create('test_job', {data: true}).save();

and kue_test2.js:

var config = require('./config');

var Kue = require('kue');

var jobs = Kue.createQueue({
    redis: {
        port: config.redis.port, 
        host: config.redis.host, 
        auth: config.redis.pass
    },
    disableSearch: true,
});

jobs.process('test_job', function(job, done) {
    console.log('recieved new job: ' + job.id);
    jobs.shutdown(function(err) {
        console.log('closing, error: ', err);
    }, 3000);
});

after run i have next output

slyder@loc03:/var/www/node/app# node kue_test2
^C
slyder@loc03:/var/www/node/app# node kue_test1
^C
slyder@loc03:/var/www/node/app# node kue_test2
recieved new job: 16
closing, error:  undefined
^C
slyder@loc03:/var/www/node/app# node kue_test2
^C
slyder@loc03:/var/www/node/app# node kue_test1
^C
slyder@loc03:/var/www/node/app# node kue_test2
recieved new job: 17
^C
slyder@loc03:/var/www/node/app#

@behrad
Copy link
Collaborator

behrad commented Sep 12, 2014

You should call done before @slyder

jobs.process('test_job', function(job, done) {
    console.log('recieved new job: ' + job.id);
    done();
    jobs.shutdown(function(err) {
        console.log('closing, error: ', err);
    }, 3000);
});

@slyder
Copy link
Author

slyder commented Sep 12, 2014

Tryed it just now, but it doesn't help:

jobs.process('test_job', function(job, done) {
    console.log('recieved new job: ' + job.id);
    console.log('MY SHUTDOWN');
    done('MY SHUTDOWN');
    jobs.shutdown(function(err) {
        console.log('closing, error: ', err);
    }, 3000);
});
slyder@loc03:/var/www/node/app# node kue_test2
recieved new job: 600
MY SHUTDOWN
closing, error:  undefined
^C
slyder@loc03:/var/www/node/app

and when i do not call done('MY SHUTDOWN'); looks like kue call done('SHUTDOWN') also, because i could see job in failed list...
but application still does not quit without CTRL+C in both cases

@behrad
Copy link
Collaborator

behrad commented Sep 12, 2014

Only the code I wrote for you was working (i.e. when calling done() without error), This was a bug in other two cases

  1. calling done(err)
  2. worker shutdown timeout because of not calling done

which I fixed and will provide you a patch just now. Thank you @slyder for reporting this 👍

@behrad behrad added the Bug label Sep 12, 2014
@behrad behrad self-assigned this Sep 12, 2014
@behrad behrad closed this as completed in 601d2c4 Sep 12, 2014
behrad added a commit that referenced this issue Sep 12, 2014
vlad-x pushed a commit to vlad-x/kue that referenced this issue Nov 11, 2014
vlad-x pushed a commit to vlad-x/kue that referenced this issue Nov 11, 2014
vlad-x pushed a commit to vlad-x/kue that referenced this issue Nov 21, 2014
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