Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delayed Job not logging in Production

I want my delayed job "code" to log in a different log file for business requirements. So I log a custom status in a log called as dj.log. Inside the "serialized" job, I am putting the log statements to log in my file.

Here is how the setup is

Delayed::Worker.destroy_failed_jobs = false
Delayed::Worker.sleep_delay = 60
Delayed::Worker.max_attempts = 10
Delayed::Worker.delay_jobs = !( Rails.env.test? || Rails.env.development? ) #dont use delayed_job in development or test mode

#Delayed_job custom logger
DJ_LOGFILE = File.join(Rails.root, 'log', 'dj.log')

and here is the job that the workers actually do

    people.each {|p| Mailer.mail(1233, p).deliver; sent_to << p.email }                
    Logger.new(DJ_LOGFILE).info("[DELIVERED] All Emails delivered (#{sent_to.join(", ")})")

what could be the problem here ? please help

like image 420
Anand Avatar asked May 31 '11 06:05

Anand


People also ask

How does a delayed job work?

Delayed::Job works by serializing a Ruby object as YAML and storing it in a database table so that a worker in a different process can retrieve, deserialize, and perform the requested work. Some operations that we use Delayed::Job for are longer-running data processing, sending emails, and updating search indicies.

How do I check if my job is delayed?

The most simple way to check whether delayed_job is running or not, is to check at locked_by field. This field will contain the worker or process locking/processing the job. Running Delayed::Job. where('locked_by is not null') will give you some results, if there are jobs running.


1 Answers

DelayedJob maintains it's own logger so you'll need to point that to your specific log file. So, in your initializer file (either environment.rb or, better, a specific delayed_job.rb file in config/initializers) add the following:

Delayed::Worker.logger = Logger.new(File.join(Rails.root, 'log', 'dj.log'))
like image 77
Olly Avatar answered Sep 19 '22 10:09

Olly