与Delayed_Job和Active Record的Rails问题

时间:2009-11-09 18:45:57

标签: ruby-on-rails delayed-job

我正在使用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 ...

谢谢!

3 个答案:

答案 0 :(得分:1)

我遇到了同样的问题并且弹出了延迟的工作,而我的服务器也解决了这个问题。

答案 1 :(得分:0)

在初始值设定项中设置Delayed::Job.destroy_failed_jobs = false,然后查看数据库中的delayed_jobs表。查找last_error错误列 - 它将具有堆栈跟踪,以便您可以诊断问题。

您可能还对delayed_job_admin插件感兴趣,该插件添加了一个控制器来查看作业。

答案 2 :(得分:0)

想出来。

这实际上是Console和Delayed_Job一起玩不好的问题。我不得不在控制台中重新定义变量,但它反映了模型中的变化。哎呦。