Delayed Job not logging in Production
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'))
log doesn't work in production with delayed job
Woody Peterson found the problem here: http://groups.google.com/group/delayed_job/browse_thread/thread/f7d0534bb6c7c83f/37b4e8ed7bfaba42
The problem is:
DJ is using Rails' buffered log in production, and flushing the buffer is not being triggered for some reason (don't know if it's flushed by buffer size or explicitly flushed after a request).
The temporary fix (credit to Nathan Phelps) is:
When in production the buffered log is set to an auto_flushing value of 1000 which means that flush is not called until 1000 messages have been logged. Assuming you're using collectiveidea's fork of delayed_job, you can address this by setting auto_flushing to a more reasonable value in command.rb right after the logger is initialized on line 64. I.E.
Delayed::Worker.logger = Rails.logger
Delayed::Worker.logger.auto_flushing = 1 # or whatever
Works for me perfectly!
Delayed Job works in development but not in production
John,
While I too used the collective Idea fork, I found that Tobi's script works too. I just need a tmp/pid directory (which you may have) and you get the log file and can cross reference this file with what your error column says in your Delayed::Job.first record (or whatever job it is of course). Script for running as a daemon from tobi fork
Oh, and you did restart, if you made changes right? Had to ask.
Delayed_job is no longer logging
I finally got this to work. All thanks to Seamus Abshere's answer to the question here. I put what he posted below in an initializer file. This got delayed_job to log to my development.rb file (huzzah!).
However, delayed_job still isn't logging into my console (for reasons I still don't understand). I solved that by opening a new console tab and entering tail -f logs/development.log
.
Different from what Seamus wrote, though, auto-flushing=true
is deprecated in Rails 4 and my Heroku app crashed. I resolved this by removing it from my initializer file and placing it in my environments/development.rb
file as config.autoflush_log = true
. However, I found that neither of the two types of flushing were necessary to make this work.
Here is his code (without the auto-flushing):
file_handle = File.open("log/#{Rails.env}_delayed_jobs.log", (File::WRONLY | File::APPEND | File::CREAT))
# Be paranoid about syncing
file_handle.sync = true
# Hack the existing Rails.logger object to use our new file handle
Rails.logger.instance_variable_set :@log, file_handle
# Calls to Rails.logger go to the same object as Delayed::Worker.logger
Delayed::Worker.logger = Rails.logger
If the above code doesn't work, try replacing Rails.logger
with RAILS_DEFAULT_LOGGER
.
delayed job starts but does not process any jobs in production
Ok so I finally got it to work, it wasn't related to delayed job at all. It had to do with the ruby gem Anemone. Anemone could not get proper authorization to the mongodb. Fixed, thanks anyways.
Rails - Delayed job stops running
Try adding this to your database.yml
reconnect: true
I am not sure if this will fix your problem, but its worth trying.
Also, have a look at this MySql documentation about lost connection
Logging in delayed_job?
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.
Related Topics
Rails:Runtimeerror - Can't Modify Frozen Array When Running Rspec in Rails
Using Activerecord Find_In_Batches Method for Deleting Large Data
Rails: Wkhtmltopdf Runtimeerror (Location of Wkhtmltopdf Unknown)
Database Cleaner Not Working in Minitest Rails
Grabbing Snapshots from Webcams in Ruby
Why Will a Range Not Work When Descending
How to Use Variables in a Yaml File
Why Require Mongo Gives Me Loaderror: No Such File to Load -- Openssl
How to Override Gemfile for Local Development
Rspec 'Eq' VS 'Eql' in 'Expect' Tests
How to Put a Delay on a Loop in Ruby
How to Use Regex for Utf8 in Ruby
Generate a Nested JSON Array in Jbuilder
How to Search Array Through Ransack Gem
How to Remove the Zone from a Datetime Value