Rails Delayed Job (DJ) 的奇怪问题

alchimie · 2013年01月30日 · 最后由 alchimie 回复于 2013年02月01日 · 2833 次阅读

perform 里的 puts 一条也没有输出,求指点 调用方法:

every(5.seconds, 'test.job') { Delayed::Job.enqueue TestJob.new }

lib/test_job.rb 
class TestJob
  def perform
    puts "TestJob is start "
    puts "=========================================="
    puts "TestJob is end "
    puts "=========================================="
  end
end

执行结果:

17:49:35 clock.1  | I, [2013-01-30T17:46:44.923628 #25713]  INFO -- : Starting clock for 1 events: [ test.job]
17:49:42 clock.1  | I, [2013-01-30T17:49:42.997396 #25817]  INFO -- : Triggering 'test.job'
17:49:48 clock.1  | I, [2013-01-30T17:49:48.104511 #25817]  INFO -- : Triggering 'test.job'

DelayedJob 没重启

楼上能否详细说明一下,DelayedJob 怎么重启,为什么不重启就不会运行呢? https://github.com/collectiveidea/delayed_job 这里好像没提到呀。。。

########################################### clock.rb 文件定义如下: require File.expand_path('../../config/boot', FILE) require File.expand_path('../../config/environment', FILE) require 'clockwork' include Clockwork

every(5.seconds, 'Queueing BaseProcessorJob job') { Delayed::Job.enqueue BaseProcessorJob.new }

class BaseProcessorJob def perform raise NotImplementedError end

def error(job, exception) Rails.logger.error "Job failed #{exception}" end end

########################################### Procfile 文件定义如下: web: bundle exec rails server worker: bundle exec rake jobs:work clock: bundle exec clockwork lib/clock.rb

########################################### 通过 foreman start 启动: 13:50:11 web.1 | started with pid 22952 13:50:11 worker.1 | started with pid 22954 13:50:11 clock.1 | started with pid 22956

########################################### 执行时 delayed_jobs.last_error 里的记录: Job failed to load: uninitialized constant BaseProcessorJob. Handler: "--- !ruby/object:BaseProcessorJob {}\n\n" /home/evan/.rvm/gems/ruby-1.9.2-p320/gems/delayed_job-3.0.4/lib/delayed/backend/base.rb:87:in rescue in payload_object' /home/evan/.rvm/gems/ruby-1.9.2-p320/gems/delayed_job-3.0.4/lib/delayed/backend/base.rb:85:inpayload_object' /home/evan/.rvm/gems/ruby-1.9.2-p320/gems/delayed_job-3.0.4/lib/delayed/backend/base.rb:95:in block in invoke_job' /home/evan/.rvm/gems/ruby-1.9.2-p320/gems/delayed_job-3.0.4/lib/delayed/lifecycle.rb:60:incall' /home/evan/.rvm/gems/ruby-1.9.2-p320/gems/delayed_job-3.0.4/lib/delayed/lifecycle.rb:60:in `block in initialize' .................................................................

需要 登录 后方可回复, 如果你还没有账号请 注册新账号