[英]Logging in delayed_job?
I can't get any log output from delayed_job
, and I'm not sure my jobs are starting.我无法从
delayed_job
获得任何日志输出,而且我不确定我的工作是否正在开始。
Here's my Procfile:这是我的 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.我也尝试过
puts
,但无济于事。
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?
这里发生了什么?
When I needed log output from Delayed Jobs, I found this question to be fairly helpful.当我需要 Delayed Jobs 的日志输出时,我发现这个问题很有帮助。
In config/initializers/delayed_job.rb
I add the line:在
config/initializers/delayed_job.rb
我添加了以下行:
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.info("Log Entry")
This results in the file log/dj.log
being written to.这导致文件
log/dj.log
被写入。 This works in development, staging, and production environments.这适用于开发、登台和生产环境。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.