mpneuried / rsmq-worker

Helper to simply implement a worker around RSMQ ( Redis Simple Message Queue )
MIT License
117 stars 24 forks source link

What is the right way to stop the worker? #11

Closed 5amfung closed 8 years ago

5amfung commented 8 years ago

For a simple example like the following, what is the right way to exit the program? I tried stop() at the end and it didn't seem to do anything.

worker.on("ready", function() {
    var i, len, msg, ref;
    ref = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
    for (i = 0, len = ref.length; i < len; i++) {
        msg = ref[i];
        console.log('SEND', msg);
        worker.send(msg);
    }
});
mpneuried commented 8 years ago

just call .stop(). https://github.com/mpneuried/rsmq-worker#stop

5amfung commented 8 years ago

That's what I thought too. Here's what I tried, but the script didn't stop. Am I missing something?

worker.start();
console.log('stop?');
worker.stop();
mpneuried commented 8 years ago

OK, now i can understand your need. You want your script to end after the .stop(), right? That was not the intension of .stop(). So i added a .quit() method with version 0.4.2.

Here's an extract of the changed docs:


.stop()

Just stop the receive interval. This will not cut the connection to rsmq/redis. If you want you script to end call .quit()

Return

( Self ): The instance itself for chaining.


.quit()

Stop the worker and close the connection. After this it's no longer possible to reuse the worker-instance. It's just intended to kill all timers and connections so your script will end.