0

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

谢谢!

4

3 回答 3

1

我遇到了同样的问题,同时延迟的工作和我的服务器都成功了。

于 2010-05-28T09:36:25.463 回答
0

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

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

于 2009-11-09T18:57:50.470 回答
0

弄清楚了。

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

于 2009-11-09T19:33:04.730 回答