2013-09-04 18 views
6

Ben gerçekten bununla aklı başındayım. Neden çalışmadığını anlamıyorum.delayed_job, bir daemon olarak çalışırken işlerini yapamaz. Tırmık işlerini kullanırken çok iyi çalışır: iş

Bir sorgulama komutunu kullanarak aradığım ve sıraya koyduğum bir sınıf yaptım. İşçiyi 'rake jobs: work' kullanarak çalıştırdığımda ve 'rake get_updates' komutunu çağırdığımda, iyi çalışır.

Ancak, çalışanı bir daemon (RAILS_ENV = production bin/delayed_job start) olarak çalıştırdığımda ve 'rake get_updates' komutunu çağırdığımda bir hata üretir.

uygulama/çalışanlar/get_updates.rb

class GetUpdates 
    def perform 

     beginning = Time.now 

     include SoapHelper 

     require 'nokogiri' 
     require 'activerecord-import' 

     product_count = 0 
     contloop = true 

     while(contloop == true) do 

      @xml = Nokogiri::XML(get_unsent_data()) 
      @guid = @xml.xpath('.//Message').attr("Id") 
      bulkUpdates = [] 

      if (@xml.xpath('.//Product').count > 0) 

       @xml.xpath('.//Product').each do |p| 

        product_count += 1 

        update = Update.new 
        update.update_type = p.attr("UpdateType") 

        codes = Hash.new 

        p.children().each do |info| 

         info.xpath('.//ProductCodes/Code').each do |coco| 
          codes[coco.attr("Scheme").to_s] = coco.content 
         end  

         update.data = p.children().to_xml.to_s 

        end 

        bulkUpdates << update 

       end 

       if Update.import bulkUpdates 

        acknowledge_soap_receipt(@guid.to_s) 

       else 

        puts "Error, data not saved" 
        contloop = false 

       end 

      else 
       contloop = false 
      end 

     end 

     @time = "Time elapsed #{Time.now - beginning} seconds" 
     puts "Product Count: #{ product_count }" 
     puts @time 

    end 
end 

clockwork.rake 'application.rb' de

task :get_updates => :environment do 

    Delayed::Job.enqueue GetUpdates.new 

end 

Autoload yolları

config.autoload_paths += %W(#{config.root}/app/workers) 
config.autoload_paths += %W(#{config.root}/app/helpers) 
hata mesajı 210

Job failed to load: undefined class/module GetUpdates. Handler: "--- !ruby/object:GetUpdates {}\n\n" /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/backend/base.rb:97:in `rescue in payload_object' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/backend/base.rb:89:in `payload_object' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/backend/base.rb:105:in `block in invoke_job' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:60:in `call' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:60:in `block in initialize' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:65:in `call' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:65:in `execute' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:38:in `run_callbacks' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/backend/base.rb:102:in `invoke_job' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/worker.rb:206:in `block (2 levels) in run' /usr/local/rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/timeout.rb:69:in `timeout' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/worker.rb:206:in `block in run' /usr/local/rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/benchmark.rb:295:in `realtime' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/worker.rb:205:in `run' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/worker.rb:267:in `block in reserve_and_run_one_job' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:60:in `call' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:60:in `block in initialize' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:65:in `call' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:65:in `execute' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:38:in `run_callbacks' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/worker.rb:267:in `reserve_and_run_one_job' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/worker.rb:189:in `block in work_off' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/worker.rb:188:in `times' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/worker.rb:188:in `work_off' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/worker.rb:153:in `block (4 levels) in start' /usr/local/rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/benchmark.rb:295:in `realtime' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/worker.rb:152:in `block (3 levels) in start' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:60:in `call' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:60:in `block in initialize' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:65:in `call' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:65:in `execute' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:38:in `run_callbacks' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/worker.rb:151:in `block (2 levels) in start' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/worker.rb:150:in `loop' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/worker.rb:150:in `block in start' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/plugins/clear_locks.rb:7:in `call' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/plugins/clear_locks.rb:7:in `block (2 levels) in <class:ClearLocks>' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:78:in `call' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:78:in `block (2 levels) in add' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:60:in `call' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:60:in `block in initialize' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:78:in `call' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:78:in `block in add' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:65:in `call' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:65:in `execute' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:38:in `run_callbacks' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/worker.rb:149:in `start' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/command.rb:104:in `run' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/command.rb:92:in `block in run_process' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/application.rb:255:in `call' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/application.rb:255:in `block in start_proc' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/daemonize.rb:82:in `call' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/daemonize.rb:82:in `call_as_daemon' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/application.rb:259:in `start_proc' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/application.rb:296:in `start' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/application_group.rb:159:in `block (2 levels) in start_all' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/application_group.rb:158:in `fork' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/application_group.rb:158:in `block in start_all' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/application_group.rb:157:in `each' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/application_group.rb:157:in `start_all' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/controller.rb:80:in `run' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons.rb:197:in `block in run_proc' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/cmdline.rb:109:in `call' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/cmdline.rb:109:in `catch_exceptions' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons.rb:196:in `run_proc' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/command.rb:90:in `run_process' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/command.rb:83:in `block in daemonize' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/command.rb:81:in `times' /usr/local/rvm/gems/ruby-1.9.3-p448/gems/delayed_job-4.0.0/lib/delayed/command.rb:81:in `daemonize' bin/delayed_job:6:in `<main>' 
+1

Uygulamanızda/worker dizini uygulamanızda $ LOAD_PATH? – adamcooke

+0

'Uygulamanın' içindeki herhangi bir şeyin otomatik olarak yüklendiği izlenimindeydim. –

+0

Bu yanlış bir izlenim. – adamcooke

cevap

4

bir in başlatıcısı sınıfı yüklemeyi deneyin işi yürütmeye çalışırken: İşe kullanılabilir yapmalıdır

# in config/initializers/delayed_job.rb 
require 'get_updates' 

.

+0

Bu dosya "delayed_job.rb" olarak adlandırılmalı mı? Şanssız bir şekilde benzer talimatları takip etmeyi denedim, ancak dosyam aynı klasörde custom.rb olarak adlandırıldı. Belli bir şekilde isimlendirilmesi gerektiğini söyleyen herhangi bir belge bulamıyorum, bu yüzden burada sormam gerektiğini düşündüm. –