我正在使用 Delayed_Job 从 API 中获取 Twitter 用户的数据,但由于某种原因它没有将其保存在模型中!请帮忙!(下面的代码)
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
结尾
澄清一下,我实际上没有收到任何错误,只是没有保存。这是我的日志的样子:
* [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 ...
谢谢!