我正在尝试在rails上使用非常基本的延迟作业:
class ImportJob < Struct.new(:job_params)
def perform
#blank perform
end
end
当我在rake中看到的所有工作排队时:工作是工作正在运行,但它永远不会完成:
Delayed::Job.enqueue ImportJob.new(job_params)
此外,如果我从rails控制台运行作业工作者,我会看到作业被“锁定”,然后立即被删除:
2.1.2 :001 > work = Delayed::Worker.new
=> #<Delayed::Worker:0x007f8a8c4d2ee8 @quiet=true, @failed_reserve_count=0>
2.1.2 :002 > work.start
Delayed::Backend::ActiveRecord::Job Load (1.8ms) SELECT "delayed_jobs".* FROM "delayed_jobs" WHERE ((run_at <= '2014-07-16 19:10:54.367527' AND (locked_at IS NULL OR locked_at < '2014-07-16 15:10:54.367862') OR locked_by = 'host:jerrods-mbp.raleigh.ibm.com pid:36564') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 5
Delayed::Backend::ActiveRecord::Job Load (3.5ms) SELECT "delayed_jobs".* FROM "delayed_jobs" WHERE ((run_at <= '2014-07-16 19:10:59.386290' AND (locked_at IS NULL OR locked_at < '2014-07-16 15:10:59.386563') OR locked_by = 'host:jerrods-mbp.raleigh.ibm.com pid:36564') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 5
SQL (5.9ms) UPDATE "delayed_jobs" SET "locked_at" = '2014-07-16 19:10:59.387743', "locked_by" = 'host:jerrods-mbp.raleigh.ibm.com pid:36564' WHERE "delayed_jobs"."id" IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE "delayed_jobs"."id" = 6 AND ((run_at <= '2014-07-16 19:10:59.386290' AND (locked_at IS NULL OR locked_at < '2014-07-16 15:10:59.386563') OR locked_by = 'host:jerrods-mbp.raleigh.ibm.com pid:36564') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC)
Delayed::Backend::ActiveRecord::Job Load (0.7ms) SELECT "delayed_jobs".* FROM "delayed_jobs" WHERE "delayed_jobs"."id" = ? LIMIT 1 [["id", 6]]
(0.1ms) begin transaction
SQL (0.5ms) DELETE FROM "delayed_jobs" WHERE "delayed_jobs"."id" = ? [["id", 6]]
(2.6ms) commit transaction
以前有没有人见过这种行为?
答案 0 :(得分:4)
好的,所以在阅读了这里和其他地方的各种其他线程后,我得到了以下解决方案:
我意识到它因任何原因无声地失败所以我添加了Delayed :: Worker.destroy_failed_jobs = false config / application.rb
添加了该行后,我可以进入控制台并获取Delayed :: Job.last.last_error,它告诉我我的作业文件因任何原因没有以rake加载
为了解决这个问题,我在initlializers中创建了一个custom.rb并添加了以下行: 要求'my_class'
希望这会帮助别人
答案 1 :(得分:0)
我在这里看不到任何与众不同的东西。作业成功完成后,将从delayed_jobs队列/数据库表中删除它。您可以让自己的工作产生错误,看看当一个人没有成功完成时会发生什么:
def perform
raise "BOOM, goes the dynamite!"
end
然而,应该输出在任何给定的&#34;运行期&#34;中成功完成的作业计数。请参阅来源here。