FooBarWidget/passenger — pull request #66 by pkmiec (2012-09-26 23:25:36+00:00)
Title: oob work for passenger 3

Please reference: https://groups.google.com/d/topic/phusion-passenger/ydmcDskBBmQ/discussion

In summary, the agent watches for the X-Passenger-Request-OOB-Work header in the response from the app process. If present, the header is removed, the response is forwarded to the client, the agent makes oobw request to the app process, app process fires the oobw event, agent returns the app process to the pool. Note, this simplified version only work with with global queue (to avoid bigger changes).

Please let me know how I can improve. I can update the docs if / when you bless the code ;).

I have the following initializer in my app,

```ruby
if defined?(::PhusionPassenger)

PhusionPassenger.on_event(:oob_work) do
t0 = Time.now
GC.start
Rails.logger.info "Completed OOB GC in #{Time.now - t0} sec"
end

class RequestOOBWork

def initialize(app, frequency)
@app = app
@frequency = frequency
@request_count = 0
end

def call(env)
@request_count += 1
status, headers, body = @app.call(env)

if @request_count % @frequency == 0
headers['X-Passenger-Request-OOB-Work'] = 'true'
end

[status, headers, body]
end

end

Rails.application.config.middleware.use RequestOOBWork, 5

end
```