gpt4 book ai didi

ruby-on-rails - Rufus 调度程序未登录生产

转载 作者:行者123 更新时间:2023-12-04 06:58:45 25 4
gpt4 key购买 nike

我的 rails 应用程序在初始化程序中使用 rufus-scheduler 启动一个进程。这是初始化程序代码的精简版本:

# config.logger isn't available here, so we have to grab it from the Rails object
logger = RAILS_DEFAULT_LOGGER

logger.warn(Time.now.to_s + ": Starting Rufus Scheduler")

# run every Wednesday at 10 AM
cron_string = '0 10 * * 3'

scheduler = Rufus::Scheduler.start_new
scheduler.cron cron_string do
logger.warn(Time.now.to_s + ": Starting Background Process")
(do work here)
logger.warn(Time.now.to_s + ": Finished Background Process")
end

logger.warn(Time.now.to_s + ": Rufus Scheduler set Background Process to run with the following cron string: [#{cron_string}]")

在所有环境中,代码都像冠军一样运行。填充过程完成它的工作并优雅地完成。然而,问题在于日志记录。当 RAILS_ENV 设置为“生产”时,cron 块内的消息根本不会记录。

我正在使用乘客 2.2.9 和 Rails 2.3.5。我认为这两件事之一是阻止进程记录日志。谁能告诉我它是哪个以及如何让它登录生产?

最佳答案

OK,找到问题了,感谢这篇文章:http://earthcode.com/blog/2009/05/rails_script_runner_logging_cron.html

原来记录器不会在生产中自动刷新。所以,我刚刚添加了

logger.flush 

到过程结束,BANG 一切正常。

关于ruby-on-rails - Rufus 调度程序未登录生产,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2210561/

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