2013-09-04 25 views
6

Jestem dosłownie na mój rozum z tego końca. Nie rozumiem, dlaczego to nie działa.delayed_job nie wykonuje zadań podczas działania jako demon. Działa dobrze podczas korzystania z rake jobs: praca

Zrobiłem klasę, którą wywołuję i umieszczam w kolejce za pomocą polecenia rake. Kiedy uruchomię robotnika za pomocą "zadań rake: praca" i wywołaj polecenie "rake get_updates", to działa ono poprawnie.

Jednak po uruchomieniu robota jako demona (RAILS_ENV = bin produkcji/delayed_job start) i wywołaniu polecenia "rake get_updates" powoduje błąd.

app/pracownicy/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

task :get_updates => :environment do 

    Delayed::Job.enqueue GetUpdates.new 

end 

ścieżki autoLoad w 'environment.rb'

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

Komunikat o błędzie podczas próby wykonać zadanie

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

Czy katalog app/workers znajduje się w aplikacji $ LOAD_PATH? – adamcooke

+0

Miałem wrażenie, że wszystko w "aplikacji" było automatycznie ładowane. –

+0

To nieprawidłowe wrażenie. – adamcooke

Odpowiedz

4

spróbuj załadować klasę do inicjowania:

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

To powinno udostępnić go do pracy.

+0

Czy ten plik musi mieć nazwę "delayed_job.rb"? Próbowałem postępować zgodnie z podobnymi instrukcjami bez powodzenia, ale mój plik nazywa się custom.rb w tym samym folderze. Nie mogę znaleźć żadnej dokumentacji, która mówi, że musi być nazwana w określony sposób, więc pomyślałem, że zapytam tutaj. –