Debugging Delayed_Jobs

I'm looking to debug a delayed jobs class. First off I added the config/initializers/delayed_job_config to move my logging to my log/production.rb file.

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

Then in the actual file I'm doing in the actual file

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

The log isn't showing anything in it. Anyone have any ideas?

Answers


I've had luck with rending the backtrace of the error to an email, which at least gives me some context of when / how the delayed job is failing:

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 your Delayed::Job tasks here is the approach I have taken. I will stub out the perform task with the expectations from the various scenarios and then test how Delayed::Job handles those results. Here is an example of how I used Delayed::Job to sync with a remote CMS nightly.

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


Need Your Help

Why isn't the cookie I'm setting in Django and reading in jQuery's cookie plugin using my expire time?

jquery python django cookies

I'm trying to create a cookie that has a specific expire time. I set it in my django view with the following code:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.