2

我的 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。我认为这两件事之一是阻止进程记录。谁能告诉我它是什么以及如何让它登录生产?

4

1 回答 1

3

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

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

logger.flush 

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

于 2010-02-05T21:38:42.120 回答