Rufus Scheduler未登录生产 [英] Rufus scheduler not logging in production

查看:104
本文介绍了Rufus Scheduler未登录生产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

在所有环境中,代码都像冠军一样运行.填充过程完成其任务并正常完成.但是,问题出在日志记录上.当RAILS_ENV设置为"production"时,cron块内的消息根本不会记录.

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.

我正在使用乘客2.2.9和Rails 2.3.5.我认为这两件事之一是阻止进程进行日志记录.谁能告诉我这是什么以及如何使其登录生产环境?

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?

推荐答案

好,找到了问题,这要归功于本文:

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 

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

to the end of the process and BANG everything worked.

这篇关于Rufus Scheduler未登录生产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆