gpt4 book ai didi

ruby-on-rails - 延迟作业记录

转载 作者:行者123 更新时间:2023-12-03 11:41:45 26 4
gpt4 key购买 nike

#Here is how I have delayed job set up.

Delayed::Worker.backend = :active_record
#Delayed::Worker.logger = Rails.logger
Delayed::Worker.logger = ActiveSupport::BufferedLogger.new("log/
##{Rails.env}_delayed_jobs.log", Rails.logger.level)
Delayed::Worker.logger.auto_flushing = 1
class Delayed::Job
def logger
Delayed::Worker.logger
end
end
if JobsCommon::check_job_exists("PeriodicJob").blank?
Delayed::Job.enqueue PeriodicJob.new(), 0, 30.seconds.from_now
end
#end


#Here is my simple job.

class PeriodicJob
def perform
Rails.logger.info "Periodic job writing #{Time.now}"
Delayed::Job.enqueue PeriodicJob.new(), 0,
30.seconds.from_now
end
end

我没有在rails日志或延迟作业日志文件中看到任何来自延迟作业的日志消息,我看到的唯一消息是delay_jobs.log文件中作业启动/成功/失败的消息。

这导致了大问题,包括检测工作人员的错误和内存泄漏几乎是不可能的!请帮忙!

最佳答案

我们已经通过入侵Rails.logger本身以使用不同的日志文件(我们希望用于delay_job条目的文件)并将其设置为使用完全相同的对象来在Rails 3 / Delayed Job 2.0.3上运行:

file_handle = File.open("log/#{Rails.env}_delayed_jobs.log", (File::WRONLY | File::APPEND | File::CREAT))
# Be paranoid about syncing, part #1
file_handle.sync = true
# Be paranoid about syncing, part #2
Rails.logger.auto_flushing = true
# Hack the existing Rails.logger object to use our new file handle
Rails.logger.instance_variable_set :@log, file_handle
# Calls to Rails.logger go to the same object as Delayed::Worker.logger
Delayed::Worker.logger = Rails.logger

如果以上代码不起作用,请尝试将 Rails.logger替换为 RAILS_DEFAULT_LOGGER

关于ruby-on-rails - 延迟作业记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3500200/

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