2

I am having many problems running DJ. Primarily, I cannot get delayed_job running any methods that change the database. I am testing locally with a sqlite3 database, DJ 3.0.0, and I even added the delayed_job_active_record gem.

I have, for example, tried to run the following method in the background:

 @user = User.find(1)
 @user.delay.recorder_method

Where this method is:

 def recorder_method
    self.relevant_field +=1
    update
 end

This creates a delayed job, and the handler has the appropriate info for the user and the appropriate method name. The script runs the job, thinks it has succeeded and thus deletes the record from the delayed_job table. BUT the user is unchanged (the database is unchanged).

What on earth is going wrong? Note that, when I run the same code ("@user.delay.recorder_method") from rails console, it works.. and the difference is the handler created by the rails console call is:

 --- !ruby/object:Delayed::PerformableMethod
    object: !ruby/ActiveRecord:User
    attributes:
        ... (attribute info and rest of file)

Whereas the one created in by the call in a controller action is:

 --- !ruby/struct:Delayed::PerformableMethod 
    object: !ruby/ActiveRecord:User 
    attributes: 

Not the difference in line 1 of both things (ruby/object vs ruby/struct.. the former works and the latter doesn't). Maybe this is something that might signal what is going wrong. Any ideas, anybody?

2 Answers 2

0

Your Rails app is running an old version of the DJ gem and your console is running a new one. About six months ago, Delayed::PerformableMethod was refactored from a Struct into a regular class: https://github.com/collectiveidea/delayed_job/commit/7b8a79a72c0ee5d8bac4bc0b183d1cce9cedff85 (So your Rails app is running a gem at least six months old and your console is running one newer than that).

This is an easy fix. First update the appropriate line in your Rails Gemfile. You'll see a line like this:

gem 'delayed_job_active_record'

If it has a version specification, make sure it's updated to the newest. Then from the command line (in the Rails root), run:

bundle update delayed_job_active_record
4
  • this seems promising, as the handler says ruby/object now. But it won't execute the task, giving an error "{You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.delete" This occurs for BOTH rails console and controller initiated delayed jobs. Ideas?
    – jay
    Mar 14, 2012 at 5:19
  • @jay, I'm unclear about what you're saying. What exactly did you run to get that error? Why task won't it execute? The bundle update? The @model.delay.method? Something else? What precisely did you change so far?
    – Ben Lee
    Mar 14, 2012 at 17:06
  • Oh.. sorry for the lack of specificity. I ran the updates that you suggested. Then I tried running the model.delay.method, and it creates a delayed job. It now has the right initial lines in the handler field (ruby/object), and it attempts to run the job - giving the nil object error. If I try running the same model.delay.method from rails console (which previously worked), this now doesn't work as well. I only ran the updates you suggested.
    – jay
    Mar 14, 2012 at 18:27
  • @jay, can you post the full stack trace for that error (not just the message)?
    – Ben Lee
    Mar 14, 2012 at 20:23
0

For anyone interested, removing the following lines from boot.rb solved this issue for me:

 require 'yaml'
 YAML::ENGINE.yamler = 'syck'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.