#Here is how I have delayed job set up. Delayed::Worker.backend = :active_record #Delayed::Worker.logger = Rails.logger Delayed::Worker.logger = ActiveSupport::BufferedLogger.new("log/ ##{Rails.env}_delayed_jobs.log", Rails.logger.level) Delayed::Worker.logger.auto_flushing = 1 class Delayed::Job def logger Delayed::Worker.logger end end if JobsCommon::check_job_exists("PeriodicJob").blank? Delayed::Job.enqueue PeriodicJob.new(), 0, 30.seconds.from_now end #end #Here is my simple job. class PeriodicJob def perform Rails.logger.info "Periodic job writing #{Time.now}" Delayed::Job.enqueue PeriodicJob.new(), 0, 30.seconds.from_now end end
I don't see any log messages from delayed job in my rails logs or delayed job log file, the only messages I see are jobs starting/success/failure in the delayed_jobs.log file.
this is causing big problems, including detecting bugs and memory leaks in workers almost impossible! Please help!
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.
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.
We've gotten it to work on Rails 3/Delayed Job 2.0.3 by hacking Rails.logger itself to use a different log file (the one we want for delayed_job entries) and also setting the delayed job logger to use the exact same object:
file_handle = File.open("log/#{Rails.env}_delayed_jobs.log", (File::WRONLY | File::APPEND | File::CREAT)) # Be paranoid about syncing, part #1 file_handle.sync = true # Be paranoid about syncing, part #2 Rails.logger.auto_flushing = 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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With