Using Que gem with Phusion Passenger
Posted by: Girish | 16 Sep 2014 | CommentsQue is a background jobs gem for Ruby and PostgreSQL, an excellent alternative to DelayedJob if you are using Postgres.
Our Tweetd project is deployed on a linode slice with nginx and Phusion Passenger.
We can run Que
workers (threads) within the web process. Que
documentation
has usage information about using unicorn
and puma
servers, but not passenger
.
After a bit of googling, came across passenger docs which says
passenger
provides PhusionPassenger.on_event(:starting_worker_process)
hook to specify our own custom code, when a new process is forked.
Finally, stuffed application.rb
with following and it worked flawlessly!
if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
if forked
# We're in smart spawning mode.
ActiveRecord::Base.establish_connection
Que.mode = :async
end
end
end