delay_job未记录 [英] delayed_job not logging

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

问题描述

我无法记录我的delay_job进程中的消息.这是正在运行的作业.

I cannot log messages from my delayed_job process. Here is the job that is being run.

class MyJob
  def initialize(blahblah)
    @blahblah = blahblah
    @logger = Logger.new(File.join(Rails.root, 'log', 'delayed_job.log'))
  end
  def perform
    @logger.add Logger::INFO, "logging from delayed_job"
    #do stuff
  end
end

我尝试了各种日志记录级别,并且我的环境配置中有config.log_level =:debug.我从monit运行delay_job.我正在将delay_job 3.0.1与ruby 1.9.3和rails 3.0.10一起使用.

I've tried various logging levels, and I have config.log_level = :debug in my environment configuration. I run delayed_job from monit. I'm using delayed_job 3.0.1 with ruby 1.9.3 and rails 3.0.10.

推荐答案

一个解释可能是作业在生产者端仅初始化一次.然后将其序列化,通过队列(例如数据库)传递,并在工作线程中取消序列化.但是不会在工作进程中再次调用initialize方法.通过发送仅调用perform方法.

An explation could be that the job gets initialized only once on producer side. Then it gets serialized, delivered through the queue (database for example) and unserialized in the worker. But the initialize method is not being called in the worker process again. Only the perform method is called via send.

但是,您可以重用worker记录器来写入日志文件:

However you can reuse the workers logger to write to the log file:

class MyJob
  def perform
    say "performing like hell"
  end

  def say(text)
    Delayed::Worker.logger.add(Logger::INFO, text)
  end
end

别忘了重新启动工作进程.

Don't forget to restart the workers.

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

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