Ruby Daemons causing ActiveRecord logger IOError

前提是你 提交于 2019-12-05 10:30:43

I ran into the same issue. You need to daemonize first, and then load the Rails environment.

the delayed_job have used daemons and activerecord, before daemonize,get the files have opend,and then reopen in daemonize

@files_to_reopen = []
ObjectSpace.each_object(File) do |file|
  @files_to_reopen << file unless file.closed?
end

Daemons.run_proc("xxxxx_name",:dir=>pid_file,:dir_mode=>:normal) do
  Dir.chdir(Rails.root)
  # Re-open file handles
  @files_to_reopen.each do |file|
    begin
      file.reopen file.path
      file.sync = true
    rescue ::Exception
    end
  end
end

It turns out that for migrations to work the ActiveRecord::Base.logger variable cannot be nil, which explains the first half of the problem. I am as yet unable to fix the IOError though when a file is used instead of STDERR.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!