Logging in delayed_job?

可紊 提交于 2019-11-30 12:40:36

问题


I can't get any log output from delayed_job, and I'm not sure my jobs are starting.

Here's my Procfile:

web:     bundle exec rails server
worker:  bundle exec rake jobs:work
worker:  bundle exec clockwork app/clock.rb

And here's the job:

class ScanningJob
  def perform
    logger.info "logging from delayed_job"
  end

  def after(job)
    Rails.logger.info "logging from after delayed_job"
  end
end

I see that clockwork outputs to system out, and I can see worker executor starting, but I never see my log statements hit. I tried puts as well to no avail.

My clock file is pretty simple:

every(3.seconds, 'refreshlistings') { Delayed::Job.enqueue ScanningJob.new }

I just want to see this working, and lack of logging means I can't. What's going on here?


回答1:


When I needed log output from Delayed Jobs, I found this question to be fairly helpful.

In config/initializers/delayed_job.rb I add the line:

Delayed::Worker.logger = Logger.new(File.join(Rails.root, 'log', 'dj.log'))

Then, in my job, I output to this log with:

Delayed::Worker.logger.debug("Log Entry")

This results in the file log/dj.log being written to. This works in development, staging, and production environments.



来源:https://stackoverflow.com/questions/14631910/logging-in-delayed-job

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