seomoz / qless

Queue / Pipeline Management
MIT License
295 stars 76 forks source link

before_fork, after_fork for forking worker #170

Closed ronalchn closed 10 years ago

ronalchn commented 10 years ago

I just did some testing in production, and found that I need to disconnect and reconnect to active_record, similar to what is done with a unicorn server.

My current workaround is to disconnect before calling the forking worker, and then establish_connection inside the job perform method.

myronmarston commented 10 years ago

The master branch already has support for after_fork via a middleware module:

module ActiveRecordReconnect
  def after_fork
    ActiveRecord::Base.establish_connection
  end
end

Qless::Workers::ForkingWorker.send(:include, ActiveRecordReconnect)

As for, before_fork: any code run before the worker starts up is before it forks, so I'm not sure we need a hook for that. Just put whatever you need before starting the worker.

Does that meet your needs?

ronalchn commented 10 years ago

Ah ok, thanks. I guess it just isn't documented because this code is new.