延迟作业入队并在数据库中出列作业但不执行代码(本地)

时间:2011-07-28 05:26:47

标签: ruby-on-rails ruby delayed-job

我使用以下代码执行延迟作业的方法:

class MyClass
   def send_a_text
      t = TwilioCommunicator.new
      t.send_sms("+15177416150","sent at #{Time.now}")
   end
   handle_asynchronously :send_a_text
end

t = MyClass.new
t.send_a_text

如果没有延迟工作,这会在100%的时间内向我发送短信。如果作业延迟,我可以看到这个作业在数据库中排队,然后出列,但代码似乎没有运行。我在本地测试,这是我的development.log的一个片段:

AREL (0.5ms)  INSERT INTO "delayed_jobs" ("priority", "attempts", "handler", "last_error", "run_at", "locked_at", "failed_at", "locked_by", "created_at", "updated_at") VALUES (0, 0, '--- !ruby/struct:Delayed::PerformableMethod 
object: !ruby/object:MyClass {}

method_name: :send_a_text_without_delay
args: []

', NULL, '2011-07-28 05:24:47.700969', NULL, NULL, NULL, '2011-07-28 05:24:47.701070', '2011-07-28 05:24:47.701070')
  AREL (2.9ms)  UPDATE "delayed_jobs" SET locked_at = '2011-07-28 05:24:51.191404', locked_by = 'delayed_job host:Stephen-B-Silverbergs-MacBook.local pid:3714' WHERE (id = 13 and (locked_at is null or locked_at < '2011-07-28 01:24:51.191404') and (run_at <= '2011-07-28 05:24:51.191404'))
  AREL (0.3ms)  DELETE FROM "delayed_jobs" WHERE ("delayed_jobs"."id" = 13)

我注意到的一件事是method_name是send_a_text_without_delay而不是send_a_text,但这是我看到的唯一奇怪的事情。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

Rails项目中的MyClass对象在哪里?如果它不在app/model中,那么您需要在初始化程序中引用该类以使Delayed_Job起作用。此问题在delayed_job中无声地失败。

请参阅:Rails Delayed Job & Library Class