我遇到了从CLI启动sidekiq的问题。当前的错误是:
`uninitialized constant ConfirmationEmailWorker::SideKiq
/Users/alexfroelich/Desktop/project/app/workers/confirmation_email_worker.rb:2:in `<class:ConfirmationEmailWorker>'
/Users/alexfroelich/Desktop/project/app/workers/confirmation_email_worker.rb:1:in `<top (required)>'
/Users/alexfroelich/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.1.0/lib/rails/engine.rb:468:in `block (2 levels) in eager_load!'
/Users/alexfroelich/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.1.0/lib/rails/engine.rb:467:in `each'
/Users/alexfroelich/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.1.0/lib/rails/engine.rb:467:in `block in eager_load!'
/Users/alexfroelich/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.1.0/lib/rails/engine.rb:465:in `each'
/Users/alexfroelich/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.1.0/lib/rails/engine.rb:465:in `eager_load!'
/Users/alexfroelich/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-3.0.0/lib/sidekiq/cli.rb:213:in `boot_system'
/Users/alexfroelich/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-3.0.0/lib/sidekiq/cli.rb:42:in `parse'
/Users/alexfroelich/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-3.0.0/bin/sidekiq:7:in `<top (required)>'
我的config/application.rb
看起来如下,因为我正在阅读eager_loading,auto_loading可能会解决问题(尽管看起来重复,因为rails会加载app/
中的所有内容)
require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)
module App
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
console do
require 'pry'
config.console = Pry
end
config.generators do |g|
g.stylesheets false
g.migration false
g.javascripts false
g.test_framework :rspec, fixture: false
g.template_engine false
end
config.autoload_paths += %W(#{config.root}/app/workers)
config.eager_load_paths += %W(#{config.root}/app/workers)
config.before_configuration do
env_file = File.join(Rails.root, 'config', 'mailer.yml')
YAML.load(File.open(env_file)).each do |key, value|
ENV[key.to_s] = value
end if File.exists?(env_file)
end
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
end
end
位于app/workers
文件夹中,我有以下文件confirmation_email_worker.rb
class ConfirmationEmailWorker
include SideKiq::Worker
def perform
DairyMailer.order_confirmation.deliver
end
end
非常难过这个..所以欢迎任何指导!感谢
答案 0 :(得分:4)
Sidekiq
只是一个单词,小写。
删除大写字母。
include Sidekiq::Worker
答案 1 :(得分:1)
请尝试这样:
class ConfirmationEmailWorker
include Sidekiq::Worker
def perform
DairyMailer.order_confirmation.deliver
end
end
将SideKiq::Worker
更改为Sidekiq::Worker
。
答案 2 :(得分:0)
使用:
class ConfirmationEmailWorker
include Sidekiq::Worker
def perform
DairyMailer.delay.order_confirmation.deliver
end
end
希望有所帮助:)