Debugging Delayed_Jobs

I am looking for debugging in slow class jobs. First, I added config / initializers / delayed_job_config to move my log to the log / production.rb file.

Delayed::Job.destroy_failed_jobs = false Delayed::Worker.logger = Rails.logger 

Then in the actual file that I am making in the actual file

 class TestJob < Struct.new() logger.debug("test logging") end 

Nothing is displayed in this log. Does anyone have any ideas?

+4
source share
2 answers

I was lucky to break the error return line into an email, which at least gives me some context of when / how the task worked with a delay:

Here is an example:

 result = Delayed::Job.work_off unless result[1].zero? ExceptionMailer.deliver_exception_message("[Delayed Job Failed] Error id: #{Delayed::Job.last.id}", Delayed::Job.last.last_error) end 

If you just want to write tests for Delayed :: Job tasks, here is my approach. I will stop the task with expectations from various scenarios, and then check how Delayed :: Job handles these results. Here is an example of how I used Delayed :: Job to synchronize with a remote nightly CMS.

 it "should sync content from the remote CMS" do CMSJobs::Sync.module_eval do def perform url.should == "http://someurl.com/tools/datafeed/resorts/all" Resort.sync_resorts!([{'id' => 1, 'name' => 'resort foo'}, { 'id' => 2, 'name' => 'resort bar' }]) end end lambda do Resort.sync_all! end.should change(Delayed::Job, :count) lambda do Delayed::Job.work_off end.should change(Resort, :count).by(2) # It should now delete a resort if it doesn't appear in the next CMS feed. lambda do Resort.sync_resorts!([{ 'id' => 2, 'name' => 'resort bar' }]) end.should change(Resort, :count).by(-1) 

end

+2
source

Have you tried to narrow it down to the fact that the delay operation has not been started or the log configuration does not work for you? What if you replace the logger.debug call with puts?

0
source

All Articles