2017-01-16 9 views
2

В моем приложении используются Sidekiq и Sidekiq-Cron для обработки заданий фона.
Оба Sidekiq и Sidekiq-Cron включены в качестве драгоценных камней в глобальную часть моего Gemfile и установлены с bundle install в моем приложении rvm gemset.синтаксическая ошибка, неожиданное keyword_end после запуска Sidekiq

После запуска в первый раз sidekiq или bundle exec sidekiq от корня моего приложения Rails, я получил следующее сообщение об ошибке, которое я прошлое и скопировать здесь для полноты картины:

[email protected]:~/workspace/fantasytennis_app (background-jobs)*$ sidekiq 
2017-01-16T09:04:36.460Z 3850 TID-7pc7o INFO: Booting Sidekiq 4.2.7 with redis options {:url=>nil} 
/home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:477:in `load': /home/asarluhi/workspace/fantasytennis_app/app/workers/check_collections_worker.rb:10: syntax error, unexpected keyword_end, expecting end-of-input (SyntaxError) 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:477:in `block in load_file' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:662:in `new_constants_in' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:476:in `load_file' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:375:in `block in require_or_load' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:37:in `block in load_interlock' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies/interlock.rb:12:in `block in loading' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/concurrency/share_lock.rb:117:in `exclusive' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies/interlock.rb:11:in `loading' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:37:in `load_interlock' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:358:in `require_or_load' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:511:in `load_missing_constant' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:203:in `const_missing' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/inflector/methods.rb:268:in `const_get' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/inflector/methods.rb:268:in `block in constantize' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/inflector/methods.rb:266:in `each' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/inflector/methods.rb:266:in `inject' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/inflector/methods.rb:266:in `constantize' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/core_ext/string/inflections.rb:66:in `constantize' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/sidekiq-cron-0.4.5/lib/sidekiq/cron/job.rb:304:in `initialize' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/sidekiq-cron-0.4.5/lib/sidekiq/cron/job.rb:186:in `new' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/sidekiq-cron-0.4.5/lib/sidekiq/cron/job.rb:186:in `block in load_from_array' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/sidekiq-cron-0.4.5/lib/sidekiq/cron/job.rb:185:in `each' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/sidekiq-cron-0.4.5/lib/sidekiq/cron/job.rb:185:in `load_from_array' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/sidekiq-cron-0.4.5/lib/sidekiq/cron/job.rb:156:in `load_from_hash' 
    from /home/asarluhi/workspace/fantasytennis_app/config/initializers/sidekiq.rb:5:in `block in <top (required)>' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/sidekiq-4.2.7/lib/sidekiq.rb:73:in `configure_server' 
    from /home/asarluhi/workspace/fantasytennis_app/config/initializers/sidekiq.rb:1:in `<top (required)>' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `block in load' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/engine.rb:648:in `block in load_config_initializer' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/notifications.rb:166:in `instrument' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/engine.rb:647:in `load_config_initializer' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/engine.rb:612:in `block (2 levels) in <class:Engine>' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/engine.rb:611:in `each' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/engine.rb:611:in `block in <class:Engine>' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:30:in `instance_exec' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:30:in `run' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:55:in `block in run_initializers' 
    from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each' 
    from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component' 
    from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from' 
    from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from' 
    from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:421:in `block in each_strongly_connected_component_from' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:44:in `each' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:44:in `tsort_each_child' 
    from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:415:in `call' 
    from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:415:in `each_strongly_connected_component_from' 
    from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component' 
    from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each' 
    from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `call' 
    from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component' 
    from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each' 
    from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:54:in `run_initializers' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/application.rb:352:in `initialize!' 
    from /home/asarluhi/workspace/fantasytennis_app/config/environment.rb:5:in `<top (required)>' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/sidekiq-4.2.7/lib/sidekiq/cli.rb:244:in `require' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/sidekiq-4.2.7/lib/sidekiq/cli.rb:244:in `boot_system' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/sidekiq-4.2.7/lib/sidekiq/cli.rb:50:in `run' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/gems/sidekiq-4.2.7/bin/sidekiq:12:in `<top (required)>' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/bin/sidekiq:23:in `load' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/bin/sidekiq:23:in `<main>' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/bin/ruby_executable_hooks:15:in `eval' 
    from /home/asarluhi/.rvm/gems/[email protected]_app_Rails5.0/bin/ruby_executable_hooks:15:in `<main>' 

Я проверил мой app/workers/check_collections_worker.rb файл, который поднимает «неожиданный keyword_end» ошибка синтаксиса в строке 3 приведенного выше кода, но нет никаких ошибок, как вы можете видеть:

Class CheckCollectionsWorker 
    include Sidekiq::Worker 

    def perform 
     collections = TennisCollection.all 
     collections.each do |collection| 
      collection.update_attribute(:check, false) 
     end 
    end 
end 

Sidekiq загружает свои рабочие места, сверху нижней части списка containe d в config/schedule.yml. Сначала загружается класс CheckCollectionsWorker, находящийся сверху.
Я попытался перейти к началу страницы, в свою очередь, каждой из заданий внутри config/schedule.yml, но для любого из них я все равно получаю сообщение об ошибке «неожиданного ключевого слова». Я уверен, что мой код верен. «Неожиданное ключевое слово_енд», сообщаемое sderr, должно быть где (и как) оно.

Ниже приводится выдержка из config/schedule.yml относительно работы коллекции:

collection_job: 
    cron: "0 20 * 1-11 1" 
    class: "CheckCollectionsWorker" 
    queue: critical 

Я скопировать и вставить config/initializers/sidekiq.rb из Sidekiq-Cron GitHub page:

Sidekiq.configure_server do |config| 
    schedule_file = "config/schedule.yml" 

    if File.exists?(schedule_file) 
    Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file) 
    end 
end 

Содержание моего config/sidekiq.yml файла находится ниже:

--- 
development: 
    :concurrency: 5 
production: 
    :concurrency: 25 
:queues: 
    - [critical, 2] 
    - default 

Я честно понятия не имею об источнике этой проблемы, так как я много раз проверял код внутри своих сотрудников и не обнаружил ошибок.

ответ

2

У вас есть опечатка в вашем работнике. Class CheckCollectionsWorker следует начинать с нижнего регистра: class