Rufus scheduler not logging in production

天大地大妈咪最大 提交于 2019-12-22 11:24:43

问题


My rails app kicks off a process with rufus-scheduler in an initializer. Here's a stripped-down version of the initializer's code:

# 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}]")

In all environments, the code runs like a champ. The populate process does its thing and finishes gracefully. The problem, however, is with logging. When RAILS_ENV is set to "production", the messages inside the cron block don't log at all.

I'm using Passenger 2.2.9 and Rails 2.3.5. I figure one of these two things is preventing the process from logging. Can anyone tell me which it is and how to get it to log in production?


回答1:


OK, found the problem, thanks to this article: http://earthcode.com/blog/2009/05/rails_script_runner_logging_cron.html

Turns out the logger will not auto-flush in production. So, I just added

logger.flush 

to the end of the process and BANG everything worked.



来源:https://stackoverflow.com/questions/2210561/rufus-scheduler-not-logging-in-production

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!