Skip to content
rdpoor edited this page Aug 10, 2011 · 19 revisions

Table of Contents

nothing happens

  1. If delayed_job appears to start but the process isn't running, check that log/delayed_job.log is writeable.
  2. Does your database includes the "delayed_job" table ? If not, go through installation instructions again.
  3. Start your app with no workers and check if jobs are added in the database. If not, see "No jobs are added in the database"
  4. If jobs are present, then launch manually one worker : "rake jobs". Jobs should be processed and disappear from the database.
    1. If jobs are still here, do they show an error ? If yes, see "jobs show an error".
    2. If jobs are no longer in the database, see log/delayed_job
    3. If jobs have been removed from the database with no reported error, see "jobs are silently removed from the database"

No jobs are added in the database

Assuming the delayed_job table is here, try to inspect the logs (log/developement.log). Do you use protection against mass assignment ? If yes, you should relax the rules for two fields :

 ActiveRecord::Base.send(:attr_accessible, :priority)
 ActiveRecord::Base.send(:attr_accessible, :payload_object)

Just like you probably did for the sessions, cf. http://railsforum.com/viewtopic.php?id=32634

jobs show an error

undefined method 'xxx' for class...

First just check if the given class has the method (never know !) Then, look closely at the 'handler' field of the job. It should be something like that (action mailer example)

 --- !ruby/struct:Delayed::PerformableMailer 
 object: !ruby/class TestMailer
 method_name: :test_email
 args: 
 - xxx@gmail.com

And NOT like that :

 --- !ruby/struct:Delayed::PerformableMailer 
 object: !ruby/object:Class TestMailer
 method_name: :test_email
 args: 
 - xxx@gmail.com

See the difference ? The second one happens when you use the 'thin' server instead of the classic mongrel ('rails server'). I don't know why. For now, the solution is to use 'rails server' instead of 'thin'.

It can also happen when using the standard Passenger/RVM setup_load_paths.rb as detailed on the RVM setup pages: https://rvm.beginrescueend.com/integration/passenger/ To solve this, simply delete that file.

jobs are silently removed from the database

If the delayed_job worker cannot process the YAML code in the 'handler' field, it will silently remove the job from the job table. One common cause is that the YAML references a class not known to the worker. If this is the case, you can add

    # file: config/initializers/custom.rb
    require 'my_custom_class'

which will force my_custom_class to be loaded when the worker starts.

Sending emails with attachments

According to the official Rails guides http://guides.rubyonrails.org/action_mailer_basics.html#adding-attachments, the mail gem will automatically guess the mime_type and set the encoding for emails with attachments. This does not work when the email is delivered asynchronously using delayed_job, and the email will be sent without the attachments.

To fix this, remember to add this line to your mailer: content_type "multipart/mixed"

Giangprosite_job

Clone this wiki locally