resque/resque — pull request #1135 by broglep-koubachi (2013-10-08 13:42:56+00:00)
Title: Add hook when process is put into the background

When resque workers are put into the background / daemonized with BACKGROUND=yes, it might be that you get "Redis::InheritedError: Tried to use a connection from a child process without reconnecting." error in cases where the redis connection was opened before the worker is put into the background (e.g. due to loading the rails environment)

We tried to fix this issues by reconnecting to redis in `before_first_hook`, but the exception we experienced are raised before the `before_first_fork` is run, namely in `prune_dead_workers`.

It is to be discussed whether a better fix would be to run the `before_first_fork` somewhere earlier, e.g. at the beginning of `startup`, instead of adding a new `after_background` hook.

Due to unclear backwards compatibility implications we decided to add a new hook right after `Process.deamon`.
This will also make sure that reconnecting to redis is performed as early as possible so that potential new code won't connect to redis before `before_first_fork` would be run.