Closed ronalchn closed 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?
Ah ok, thanks. I guess it just isn't documented because this code is new.
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 jobperform
method.