let workers exit gracefully #282

Merged
merged 2 commits into from Feb 6, 2014

Projects

None yet

2 participants

@bkw
Contributor
bkw commented Feb 6, 2014

This PR lets workers finish handling the current batch before exiting gracefully. This not only avoids errors in the rabbitmq logs, but it should also reduce lost messages (we ack before postprocessing, another PR that fixes this is in the works).

I try to keep these PRs atomic, but splitting them up makes them conflict with one another. Sorry for that, I'll be happy to rebase on request.

Contributor
bkw commented Feb 6, 2014

sorry, forgot to fix the tests. Will do.

Contributor
bkw commented Feb 6, 2014

just force-pushed a rebased version of this

@SandyWalsh SandyWalsh commented on the diff Feb 6, 2014
worker/worker.py
@@ -144,9 +147,14 @@ def on_nova(self, body, message):
(e, json.loads(str(message.body))))
raise
+ def _shutdown(self, signal, stackframe = False):
+ global shutdown_soon
+ self.should_stop = True
SandyWalsh
SandyWalsh Feb 6, 2014 Contributor

Where is this used?

bkw
bkw Feb 6, 2014 Contributor

self._shutdown is registered as a handler for signal TERM, since that is what start_workers.py does to us when it shuts down.

bkw
bkw Feb 6, 2014 Contributor

Or you mean should_stop? That's a kombu mixin thing, letting the consumer exit after it's done processing a message.

Contributor

signal support is great ... just a minor question. May need a rebase too.

Contributor
bkw commented Feb 6, 2014

i pushed the rebased version, anything else I can do?

Contributor

Ah, the mixin ... forgot about that! Thanks (I wonder if we should note that in a comment?)

@SandyWalsh SandyWalsh merged commit af8c27d into rackerlabs:master Feb 6, 2014

1 check passed

default The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment