我的应用程序使用Sidekiq
和Sidekiq-Cron
进行后台作业处理。
Sidekiq和Sidekiq-Cron都作为gems包含在我的Gemfile的global部分中,并与bundle install
我的应用程序的rvm gemset一起安装。
首次启动sidekiq
或bundle exec sidekiq
从我的Rails应用程序的根目录启动后,我收到以下错误消息,我将其复制并复制到此处以确保完整性:
asarluh[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/ruby-2[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
文件,这在上面的代码的第3行中引发了“意外的keyword_end”语法错误,但是没有错误,如您所见:
Class CheckCollectionsWorker
include Sidekiq::Worker
def perform
collections = TennisCollection.all
collections.each do |collection|
collection.update_attribute(:check, false)
end
end
end
Sidekiq从中包含的列表的顶部到底部加载其作业config/schedule.yml
。的CheckCollectionsWorker
类,在顶部,首先被加载。
我试图依次移到其中的每个作业的顶部config/schedule.yml
,但对于其中的任何作业,我始终收到相同的“意外的keyword_end”错误消息。我确定我的代码是正确的。sderr报告的“意外的keyword_end”应位于(和保持)原位置。
以下是config/schedule.yml
有关收集工作的摘录:
collection_job:
cron: "0 20 * 1-11 1"
class: "CheckCollectionsWorker"
queue: critical
我config/initializers/sidekiq.rb
从Sidekiq-Cron GitHub页面复制并粘贴:
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
老实说,我对这个问题的根源一无所知,因为我检查了工人内部的代码很多次,没有发现任何错误。
你的工人有错字。Class CheckCollectionsWorker
应该以小写字母开头:class
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句