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

Shutdown not a function #783

Closed
GINNOV opened this issue Dec 18, 2015 · 16 comments
Closed

Shutdown not a function #783

GINNOV opened this issue Dec 18, 2015 · 16 comments

Comments

@GINNOV
Copy link

GINNOV commented Dec 18, 2015

Hello Kue team,

I have the following error

💥
queue.shutdown(2000, function(err) {
^
TypeError: queue.shutdown is not a function
at null. (/home/pi/code/iamsblog/sleepia/slogger.js:39:9)
at emitNone (events.js:67:13)
at emit (events.js:166:7)

From the documentation and the adviced received it all seems that I am doing the right thing, but the error still throwing.

I looked at this closed issues:

My code (gist)

var kue = require('kue'); 
var queue = kue.createQueue({
    prefix: 'q',
    redis: {
        port: 6379,
        host: 'localhost',
        auth: '', 
        db: 0,
        options: {
        }
    }
});

// somewhere else... this is the throwing the error.
queue.shutdown(2000, function(err) {
            console.log('# Shutting down: ', err || '');
        });

Any help is appreciated and happy holidays!
;mE

@behrad
Copy link
Collaborator

behrad commented Dec 19, 2015

Strange.... Can you debug what is exactly inside your queue variable, and why shutdown is not there?

@ghost
Copy link

ghost commented Dec 20, 2015

queue contains {RedisClient} as expected as it does connect to the server and writing operations occured as expected.

On the offending line that shows the exception, queue still not null. The debugger (VS Code on OS X) didn't let me dig further.

I was able to replicate the problem without any additional package that I was using and pretty straightforward for what concern the usage of Kue. In the process I also found another issue for the graceful shutdown operation. See below for details.

/*
 repro issue #783 for Kue
*/

var kue = require('kue'); // queue management library
var queue = kue.createQueue({
    prefix: 'q',
    redis: {
        port: 6379,
        host: 'localhost',
        auth: '', 
        db: 0, 
        options: {

        }
    }
});

var counterToStopWork = 0;

/* simple-job-queue */

function newJob(name) {
    name = name || 'Default_Name';
    var job = queue.create('new job', {
        name: name
    });
    job
        .on('complete', function() {
            console.log('Job', job.id, 'with name', job.data.name, 'is    done');
        })
        .on('failed', function() {
            console.log('Job', job.id, 'with name', job.data.name, 'has  failed');
        });
    job.save();
}

queue.process('new job', function(job, done) {
    /* carry out all the job function here */
    done && done();
});

setInterval(function() {
    newJob('Send_Email');
    counterToStopWork = counterToStopWork +1;
    if (counterToStopWork == 5) {
        queue.shutdown(2000, function(err) {
            console.log('# Shutting down: ', err || '');
        });
    }
}, 3000);

//
// Shutdown grecefully if CTRL+C is pressed
//
// --->> DOESN'T WORK WHEN CTRL + C IS PRESSED IN TERMINAL  <<<---
//
process.once('SIGTERM', function(sig) {

    queue.shutdown(5000, function(err) {
        console.log('# Graceful shutdown started: ', err || '');
        process.exit(0);
    });
});

@behrad
Copy link
Collaborator

behrad commented Dec 21, 2015

Please make sure Ctrl+C on your terminal sends SIGTERM to your process. you can do this by adding a log before queue.shutdown call.

@ghost
Copy link

ghost commented Dec 22, 2015

I checked the documentation and it seems that the default ctrl+c on OSX sends a SIGTERM
this also confirms that
http://superuser.com/questions/419339/quit-an-application-in-os-x-terminal

@behrad
Copy link
Collaborator

behrad commented Dec 22, 2015

add a log to that line and test it your self in your console please that
SIGTERM callback is called

2015-12-22 4:39 GMT+03:30 Mario notifications@github.com:

I checked the documentation and it seems that the default ctrl+c on OSX
sends a SIGTERM
this also confirms that
http://superuser.com/questions/419339/quit-an-application-in-os-x-terminal


Reply to this email directly or view it on GitHub
#783 (comment).

--Behrad

@ghost
Copy link

ghost commented Dec 22, 2015

Just to be clear, the main issue here is that shutdown throws an exception as reported.
I know for a fact that that call callback is not called because the same line of code that cause the shutdown to fail is in that routine.

According to the documentation, my term (OSX) is configured by default to send a SIGTERM signal. In all cases that for me is not a scenario as I want to shutdown remotely (I have a hardware switch that works as expected for the callback purposes)

@behrad
Copy link
Collaborator

behrad commented Dec 22, 2015

Can you print out whats inside your queue object?

@ghost
Copy link

ghost commented Dec 22, 2015

Already done, It reported in my issue.
{RedisClient}

it's a valid object ref as using that object I can read and write into redis.

@behrad
Copy link
Collaborator

behrad commented Dec 22, 2015

It should've been a Queue object not a RedisClient.
Can you post a code that re-produces the same issue!?

@ghost
Copy link

ghost commented Dec 22, 2015

I did post the code to repro in this thread.
Here it is the direct link #783 (comment)

@behrad
Copy link
Collaborator

behrad commented Dec 22, 2015

does seem a normal code! I'll try to run it locally.
What is your node and redis version?

@ghost
Copy link

ghost commented Dec 22, 2015

yep, that is what lead me to file the issue. It should just work.
redis: 3.0.5
config file, default settings
node v5.1.0
platform OSX - El Capitan

@ghost
Copy link

ghost commented Dec 22, 2015

There was enough evidence but just to be double sure I step into the debugger a little further to validate your comment about the returning type. It is not a Queue object.

/**
 * Create a new `Queue`.
 *
 * @return {Queue}
 * @api public
 */

exports.createQueue = function(){
  return Queue.singleton = new Queue;
};

/**
 * Initialize a new job `Queue`.
 *
 * @api public
 */

function Queue() {
  this.client = redis.createClient();
}

@behrad
Copy link
Collaborator

behrad commented Dec 22, 2015

@ghost
Copy link

ghost commented Dec 22, 2015

oh. Then in that case has to be something related with the packaging/modules. I will investigate and report back.

@GINNOV
Copy link
Author

GINNOV commented Dec 23, 2015

after you pointed out the disparity of the returing object I figured what was the issue.
I deleted the cache for the kue module and added ^ symbol in replace of the ~ to force the use of the latest which I was already using from the signature point of view. Kaboow it works. Thanks for looking into this!

@GINNOV GINNOV closed this as completed Dec 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants