Asarluhi
Asarluhi

Reputation: 1290

syntax error, unexpected keyword_end after launching Sidekiq

My application uses Sidekiq and Sidekiq-Cron for background job processing.
Both Sidekiq and Sidekiq-Cron are included as gems in the global section of my Gemfile, and installed with bundle install in my application's rvm gemset.

After launching for the first time sidekiq or bundle exec sidekiq from the root of my Rails application, I received the following error message which I past and copy here for completeness:

asarluhi@home:~/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/ruby-2.3.1@fantasytennis_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/ruby-2.3.1@fantasytennis_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/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:662:in `new_constants_in'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:476:in `load_file'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_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/ruby-2.3.1@fantasytennis_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/ruby-2.3.1@fantasytennis_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/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/concurrency/share_lock.rb:117:in `exclusive'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies/interlock.rb:11:in `loading'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:37:in `load_interlock'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:358:in `require_or_load'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:511:in `load_missing_constant'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:203:in `const_missing'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/inflector/methods.rb:268:in `const_get'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_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/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/inflector/methods.rb:266:in `each'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/inflector/methods.rb:266:in `inject'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/inflector/methods.rb:266:in `constantize'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_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/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/sidekiq-cron-0.4.5/lib/sidekiq/cron/job.rb:304:in `initialize'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/sidekiq-cron-0.4.5/lib/sidekiq/cron/job.rb:186:in `new'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_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/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/sidekiq-cron-0.4.5/lib/sidekiq/cron/job.rb:185:in `each'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/sidekiq-cron-0.4.5/lib/sidekiq/cron/job.rb:185:in `load_from_array'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_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/ruby-2.3.1@fantasytennis_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/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `block in load'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_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/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/notifications.rb:166:in `instrument'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/engine.rb:647:in `load_config_initializer'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_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/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/engine.rb:611:in `each'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/engine.rb:611:in `block in <class:Engine>'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:30:in `instance_exec'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:30:in `run'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_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/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:44:in `each'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_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/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:54:in `run_initializers'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_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/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/sidekiq-4.2.7/lib/sidekiq/cli.rb:244:in `require'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/sidekiq-4.2.7/lib/sidekiq/cli.rb:244:in `boot_system'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/sidekiq-4.2.7/lib/sidekiq/cli.rb:50:in `run'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/sidekiq-4.2.7/bin/sidekiq:12:in `<top (required)>'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/bin/sidekiq:23:in `load'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/bin/sidekiq:23:in `<main>'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/bin/ruby_executable_hooks:15:in `eval'
    from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/bin/ruby_executable_hooks:15:in `<main>'

I checked my app/workers/check_collections_worker.rb file, which raises the "unexpected keyword_end" syntax error in line 3 of the above code, but there are no errors, as you can see:

Class CheckCollectionsWorker
    include Sidekiq::Worker

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

Sidekiq loads its jobs from top to bottom of a list contained in config/schedule.yml. The CheckCollectionsWorker class, being at the top, is loaded first.
I tried to move to the top in turn each of the jobs inside config/schedule.yml, but for any of them I keep receiving the same "unexpected keyword_end" error message. I am sure my code is correct. The "unexpected keyword_end" reported by sderr should be where (and as) it is.

Below is an extract of config/schedule.yml concerning the collection job:

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

I copied and pasted config/initializers/sidekiq.rb from the 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

The content of my config/sidekiq.yml file is below:

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

I honestly have no idea about the source of this issue, since I checked many times the code inside my workers and found no errors.

Upvotes: 2

Views: 614

Answers (1)

Slava.K
Slava.K

Reputation: 3080

You have a typo in your worker. Class CheckCollectionsWorker should begin with lowercase: class

Upvotes: 2

Related Questions