Skip to content

Conversation

@sheltond
Copy link
Contributor

@sheltond sheltond commented Aug 1, 2014

I implemented this because I was having the same problem as johnkchow who opened issue #562: I use a system which does operations in a background thread within a Rails process, and I need to defer the shutdown of Puma worker processes until any background operations are done.

This patch just calls an array of hooks immediately before the worker exits (after it has stopped accepting connections), and blocks until the hooks return.

The user can add an "on_worker_shutdown" section in their Puma configuration file where they can call whatever function they need to block until their background jobs are finished.

@@ -176,7 +176,9 @@ def shutdown

# Use this instead of #each so that we don't stop in the middle
# of each and see a mutated object mid #each
@workers.first.join until @workers.empty?
if [email protected]?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you fix the formatting of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry about that. Should be fixed now.

On Mon, Aug 4, 2014 at 5:11 PM, Evan Phoenix [email protected]
wrote:

In lib/puma/thread_pool.rb:

@@ -176,7 +176,9 @@ def shutdown

   # Use this instead of #each so that we don't stop in the middle
   # of each and see a mutated object mid #each

Can you fix the formatting of this?


Reply to this email directly or view it on GitHub
https://github.com/puma/puma/pull/566/files#r15763791.

evanphx added a commit that referenced this pull request Nov 24, 2014
Added on_worker_shutdown mechanism
@evanphx evanphx merged commit 2630730 into puma:master Nov 24, 2014
@drush
Copy link

drush commented Feb 20, 2015

@sheltond Do you have some sample code where you utilize this for background threads that start cleanly and close gracefully? Just looking to make sure signal hooks are used if needed, etc.

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

Successfully merging this pull request may close these issues.

3 participants