【发布时间】:2012-03-29 23:32:42
【问题描述】:
我是第一次处理延迟的工作,我没有任何运气让它工作,我不明白为什么。作业排队,但从不执行。虽然它确实从数据库中删除了,所以工作人员似乎正在处理它,但它从来没有运行它看起来的 perform 方法。
我已经设置了以下初始化器:
require 'delayed/worker'
Dir.glob("./app/jobs/*.rb").each { |f| require f }
Delayed::Worker.logger = ActiveSupport::BufferedLogger.new("log/dj.log", Rails.logger.level)
module Delayed
class Worker
def self.dj_say(text)
self.logger.info "#{Time.now.strftime('%F %T %z')}: #{text}"
end
end
end
初始化程序工作,并且在工作开始/退出时确实会写入 dj.log。
我的工作包括以下内容:
class UpdateServices
attr_accessor :options
def initialize(options)
self.options = options
end
def perform
#Debugging code
Delayed::Worker.dj_say "starting"
File.open("tmp/test.txt","w").close
#End debugging code
#bunch-o-code-here
Delayed::Worker.dj_say "completed"
end
end
这些代码都没有运行过。我尝试将调试代码添加到 perform 方法中,但它永远不会被执行,所以肯定有什么事情发生了。我从这样的模型中调用工作:
class Service < ActiveRecord::Base
def start_updating!(options)
Delayed::Job.enqueue(UpdateServices.new(options), :priority => 0, :run_at => 30.seconds.from_now, :queue => 'update_services')
end
end
该模型是从我的控制器中调用的,如下所示:
Service.new.start_updating!(params)
我唯一的猜测是我被错误地称为 Delayed::Job.enqueue,但根据我所阅读的所有内容,这似乎应该是这样做的。
【问题讨论】:
标签: ruby ruby-on-rails-3 delayed-job