我的 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 块内的消息根本不会记录。
我正在使用 Passenger 2.2.9 和 Rails 2.3.5。我认为这两件事之一是阻止进程记录。谁能告诉我它是什么以及如何让它登录生产?
好的,找到问题了,感谢这篇文章:http://earthcode.com/blog/2009/05/rails_script_runner_logging_cron.html http://earthcode.com/blog/2009/05/rails_script_runner_logging_cron.html
结果记录器不会在生产中自动刷新。所以,我刚刚添加了
logger.flush
到过程结束时,一切都顺利了。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)