Rails Resque workers fail with PGError: server closed the connection unexpectedly

后端 未结 5 1147
抹茶落季
抹茶落季 2020-12-07 23:42

I have site running rails application and resque workers running in production mode, on Ubuntu 9.10, Rails 2.3.4, ruby-ee 2010.01, PostgreSQL 8.4.2

Workers constantl

5条回答
  •  独厮守ぢ
    2020-12-08 00:08

    After doing a bit of research / trial and error. For anyone who is coming across the same issue. To clarify what gc mentioned.

    Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }
    

    Above code should be placed in: /lib/tasks/resque.rake

    For example:

    require 'resque/tasks'
    
    task "resque:setup" => :environment do
      ENV['QUEUE'] = '*'
    
      Resque.after_fork do |job|
        ActiveRecord::Base.establish_connection
      end
    
    end
    
    desc "Alias for resque:work (To run workers on Heroku)"
    task "jobs:work" => "resque:work"
    

    Hope this helps someone, as much as it did for me.

提交回复
热议问题