gpt4 book ai didi

ruby-on-rails - 日志在延迟作业的生产中不起作用

转载 作者:数据小太阳 更新时间:2023-10-29 08:34:53 27 4
gpt4 key购买 nike

我遇到了一些奇怪的问题,我的 delayed_jobs 在生产中失败了。最后我把范围缩小到记录器。如果我注释掉我的日志函数调用,一切正常。但是,如果我尝试记录,我会在 delayed_job 处理程序中得到这个:

 --- !ruby/struct:Delayed::PerformableMethod 
object: AR:User:1
method: :load_and_update_without_send_later
args: []

| closed stream
/opt/ruby/lib/ruby/1.8/logger.rb:504:in `write'
/opt/ruby/lib/ruby/1.8/logger.rb:504:in `write'
/opt/ruby/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/opt/ruby/lib/ruby/1.8/logger.rb:496:in `write'
/opt/ruby/lib/ruby/1.8/logger.rb:326:in `add'
/opt/ruby/lib/ruby/1.8/logger.rb:374:in `info'
/home/rails/myapp.com/releases/20100203203031/app/models/gmail.rb:35:in `log'

我的记录器看起来像这样:

@@error_log_file = File.open("#{RAILS_ROOT}/log/error.log", 'a')
@@error_log_file.sync = true
def log(msg)
msg.each do |line|
line = "#{Time.now.strftime('%H:%M:%S')} #{line}"
@@error_log_file.info(line) # this is line 35 where it's failing
puts line
end
end

如果我注释掉“@@error_log_file.sync = true”这行,它也可以。

这是一个延迟的工作问题,还是与我的日志目录是一个符号链接(symbolic link)(由标准 capistrano 部署设置)有关?

也没有任何内容写入我的 error.log 文件,也没有任何内容写入 delayed_job.log。完全难住了...

最佳答案

Woody Peterson 在这里发现了问题:http://groups.google.com/group/delayed_job/browse_thread/thread/f7d0534bb6c7c83f/37b4e8ed7bfaba42

问题是:

DJ is using Rails' buffered log in production, and flushing the buffer is not being triggered for some reason (don't know if it's flushed by buffer size or explicitly flushed after a request).

临时修复(归功于 Nathan Phelps)是:

When in production the buffered log is set to an auto_flushing value of 1000 which means that flush is not called until 1000 messages have been logged. Assuming you're using collectiveidea's fork of delayed_job, you can address this by setting auto_flushing to a more reasonable value in command.rb right after the logger is initialized on line 64. I.E.

Delayed::Worker.logger = Rails.logger

Delayed::Worker.logger.auto_flushing = 1 # or whatever

非常适合我!

关于ruby-on-rails - 日志在延迟作业的生产中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2195410/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com