Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging in delayed_job?

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?

like image 247
Stefan Kendall Avatar asked Jan 31 '13 17:01

Stefan Kendall


1 Answers

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.info("Log Entry") 

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

like image 160
James Chevalier Avatar answered Sep 23 '22 23:09

James Chevalier