45

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?

deefour
  • 34,974
  • 7
  • 97
  • 90
Stefan Kendall
  • 66,414
  • 68
  • 253
  • 406
  • possible duplicate of [delayed\_job not logging](http://stackoverflow.com/questions/9507765/delayed-job-not-logging) – deefour Jan 31 '13 at 17:49

1 Answers1

107

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.

James Chevalier
  • 10,604
  • 5
  • 48
  • 74
  • 1
    Note `logger.debug` logs may be hidden by default depending on your setup, so I recommend using `logger.info` instead which is one level higher. – Kevin Cooper Feb 19 '20 at 00:55