nevans/resque-pool — pull request #85 by joshuaflanagan (2013-10-13 21:12:22+00:00)
Title: Enable custom logic to determine worker configuration

This change introduces the concept of a *configuration loader*.

> This is intended to replace our team's other PR https://github.com/nevans/resque-pool/pull/84, which Matt closed

To provide your own configuration logic, you set the `configuration_loader` class variable on Resque::Pool to an object that responds to `#call` (which can simply be a lambda/Proc).
It also allows more realtime configuration changes by polling the configuration loader each time a job completes. Configuration loaders can optionally implement a `#reset!` method if they want to re-initialize when the HUP signal is received.

For example, if you wanted to vary the number of worker processes based on a
value stored in Redis, you could do something like:

```ruby
task resque:pool:setup do
Resque::Pool.config_loader = lambda {|env|
worker_count = Redis.current.get("pool_workers_#{env}").to_i
{"queueA,queueB" => worker_count }
}
end
```

Simply changing the value in Redis would allow the pool to dynamically change, without having to send the HUP signal.

This PR will replace the need for changes like https://github.com/nevans/resque-pool/pull/69, https://github.com/nevans/resque-pool/pull/62, and https://github.com/nevans/resque-pool/issues/21, since they can be implemented as custom configuration loaders.

All of the previous configuration logic has been moved to the `FileOrHashLoader` class. There are a few quirks to the original behavior, so it was simpler to keep it a single source for now. This can likely be simplified if we do not need to keep all of the original behavior. For example, if the ability to load from a `Hash` is used solely for testing, all of that logic could likely be removed, and tests can just specify a lambda that returns a `Hash`.