views:

274

answers:

4

I'm using Delayed_Job to grab a Twitter user's data from the API, but it's not saving it in the model for some reason! Please help! (code below)

class BandJob < Struct.new(:band_id, :band_username) #parameter

  def perform
    require 'json'
    require 'open-uri'
    band = Band.find_by_id(band_id)
    t = JSON.parse(open("http://twitter.com/users/show/#{band_username}.json").read)
    band.screen_name = t['screen_name']
    band.profile_background_image = t['profile_background_image_url']
    band.url = 'http://' + band_username + '.com'
    band.save!
  end

end

To clarify, I'm actually not getting any errors, it's just not saving. Here's what my log looks like:

* [JOB] acquiring lock on BandJob
  [4;36;1mDelayed::Job Update (3.1ms)[0m   [0;1mUPDATE "delayed_jobs" SET locked_at = '2009-11-09 18:59:45', locked_by = 'host:dhcp128036151228.central.yale.edu pid:2864' WHERE (id = 10442 and (locked_at is null or locked_at < '2009-11-09 14:59:45') and (run_at <= '2009-11-09 18:59:45')) [0m
  [4;35;1mBand Load (1.5ms)[0m   [0mSELECT * FROM "bands" WHERE ("bands"."id" = 34) LIMIT 1[0m
  [4;36;1mBand Update (0.6ms)[0m   [0;1mUPDATE "bands" SET "updated_at" = '2009-11-09 18:59:45', "profile_background_image" = 'http://a3.twimg.com/profile_background_images/38193417/fbtile4.jpg', "url" = 'http://Coldplay.com', "screen_name" = 'coldplay' WHERE "id" = 34[0m
  [4;35;1mDelayed::Job Destroy (0.5ms)[0m   [0mDELETE FROM "delayed_jobs" WHERE "id" = 10442[0m
* [JOB] BandJob completed after 0.5448
1 jobs processed at 1.8011 j/s, 0 failed ...

Thanks!

A: 

Set Delayed::Job.destroy_failed_jobs = false in an initializer, then take a look at the delayed_jobs table in your database. Look for the last_error error column -- that will have the stack trace so you can diagnose the problem.

You may also be interested in the delayed_job_admin plugin, which adds a controller to view jobs.

Luke Francl
thanks a lot for the quick feedback! the weird this is I'm not getting any errors... it's just not saving!
Michael Waxman
A: 

Figured it out.

It was actually an issue with the Console and Delayed_Job not playing nice together. I had to redefine the variable in the console, but then it reflected the changes in the model. Whoops.

Michael Waxman
A: 

Can you post a more detailed solution? I'm having the exact same problem!

Filip Tepper
A: 

I had the same problem and bouncing both delayed job and my server did the trick.

Ben