46

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

1 Answer 1

110

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.

1
  • 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. Commented Feb 19, 2020 at 0:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.