Added on_worker_shutdown mechanism

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.
Yes, sorry about that. Should be fixed now.


On Mon, Aug 4, 2014 at 5:11 PM, Evan Phoenix <notifications@github.com>
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
> > -      @workers.first.join until @workers.empty?
> > +	  if !@workers.empty?
>
> 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>.
>