生产中的 Shopify/money gem:“未初始化的常量 ActiveJob::Serializers”

问题描述 投票:0回答:1

我正在尝试更新旧的 Rails 应用程序以在 heroku-20 堆栈上运行。我正在运行 Rails 5.1.1 和 shopify-money 1.1.2。它在本地工作,一切似乎都正确部署到 heroku,但是当我尝试启动应用程序时,出现以下错误:

gems/shopify-money-1.1.2/lib/money/rails/job_argument_serializer.rb:5:in 'module:Rails': uninitialized constant ActiveJob::Serializers (NameError)

我尝试重新加载数据库时收到更完整的错误消息:

heroku run bundle exec rake db:reload -a kiddocloud-staging
Running bundle exec rake db:reload on ⬢ kiddocloud-staging... up, run.3483 (Eco)
W, [2023-05-04T22:55:19.644207 #2]  WARN -- sentry: ** [Raven] You are running on Heroku but haven't enabled Dyno Metadata. For Sentry's release detection to work correctly, please run `heroku labs:enable runtime-dyno-metadata`
D, [2023-05-04T22:55:19.708017 #2] DEBUG -- : uninitialized constant ActiveJob::Serializers excluded from capture: DSN not set
rake aborted!
NameError: uninitialized constant ActiveJob::Serializers
/app/vendor/bundle/ruby/2.6.0/gems/shopify-money-1.1.2/lib/money/rails/job_argument_serializer.rb:5:in `<module:Rails>'
/app/vendor/bundle/ruby/2.6.0/gems/shopify-money-1.1.2/lib/money/rails/job_argument_serializer.rb:4:in `<class:Money>'
/app/vendor/bundle/ruby/2.6.0/gems/shopify-money-1.1.2/lib/money/rails/job_argument_serializer.rb:3:in `<top (required)>'
/app/vendor/bundle/ruby/2.6.0/gems/shopify-money-1.1.2/lib/money/railtie.rb:7:in `require_relative'
/app/vendor/bundle/ruby/2.6.0/gems/shopify-money-1.1.2/lib/money/railtie.rb:7:in `block (2 levels) in <class:Railtie>'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.1/lib/active_support/lazy_load_hooks.rb:45:in `instance_eval'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.1/lib/active_support/lazy_load_hooks.rb:45:in `execute_hook'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.1/lib/active_support/lazy_load_hooks.rb:35:in `block in on_load'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.1/lib/active_support/lazy_load_hooks.rb:34:in `each'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.1/lib/active_support/lazy_load_hooks.rb:34:in `on_load'
/app/vendor/bundle/ruby/2.6.0/gems/shopify-money-1.1.2/lib/money/railtie.rb:6:in `block in <class:Railtie>'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.1.1/lib/rails/initializable.rb:30:in `instance_exec'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.1.1/lib/rails/initializable.rb:30:in `run'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.1.1/lib/rails/initializable.rb:59:in `block in run_initializers'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.1.1/lib/rails/initializable.rb:58:in `run_initializers'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.1.1/lib/rails/application.rb:353:in `initialize!'
/app/config/environment.rb:5:in `<top (required)>'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.1.1/lib/rails/application.rb:329:in `require_environment!'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.1.1/lib/rails/application.rb:445:in `block in run_tasks_blocks'
/app/vendor/bundle/ruby/2.6.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/cli/exec.rb:74:in `load'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/cli/exec.rb:74:in `kernel_load'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/cli/exec.rb:28:in `run'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/cli.rb:463:in `exec'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/cli.rb:27:in `dispatch'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/cli.rb:18:in `start'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/exe/bundle:30:in `block in <top (required)>'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/exe/bundle:22:in `<top (required)>'
/app/bin/bundle:3:in `load'
/app/bin/bundle:3:in `<main>'
Tasks: TOP => db:reload => environment
(See full trace by running task with --trace)

其实是一样的。它似乎无法找到 ActiveJob::Serializers 即使 Rails 5.0.0 及更高版本应该有......帮助!

编辑:这是我的内容

application.rb

require_relative 'boot'

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module Kidsclub
  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.
    #config.autoload_paths += %W(#{config.root}/lib)
    config.autoload_paths += Dir["#{config.root}/lib/**/"]
    config.autoload_paths += Dir[Rails.root.join('app', 'models', '**/')]
    config.autoload_paths += Dir[Rails.root.join('app', 'exceptions', '**/')]
    config.autoload_paths += Dir[Rails.root.join('app', 'enums', '**/')]
    config.eager_load_paths << "#{Rails.root}/lib"
    config.assets.paths << "#{Rails.root}/app/assets"

    config.time_zone = "Pacific Time (US & Canada)"

    config.active_job.queue_adapter = :async
  end
end

这是我的

production.rb
(我没有看到任何敏感信息):

Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.rb.

  # Code is not reloaded between requests.
  config.cache_classes = true

  # Eager load code on boot. This eager loads most of Rails and
  # your application in memory, allowing both threaded web servers
  # and those relying on copy on write to perform better.
  # Rake tasks automatically ignore this option for performance.
  config.eager_load = true

  # Full error reports are disabled and caching is turned on.
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  # Disable serving static files from the `/public` folder by default since
  # Apache or NGINX already handles this.
  config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?

  # Compress JavaScripts and CSS.
  config.assets.js_compressor = :uglifier
  config.assets.css_compressor = :sass

  # Do not fallback to assets pipeline if a precompiled asset is missed.
  config.assets.compile = false

  config.public_file_server.enabled = true

  # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb

  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
  # config.action_controller.asset_host = 'http://assets.example.com'

  # Specifies the header that your server uses for sending files.
  # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX

  # Mount Action Cable outside main process or domain
  # config.action_cable.mount_path = nil
  # config.action_cable.url = 'wss://example.com/cable'
  # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]

  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
  config.force_ssl = true

  # Use the lowest log level to ensure availability of diagnostic information
  # when problems arise.
  config.log_level = :debug

  # Prepend all log lines with the following tags.
  config.log_tags = [ :request_id ]

  # Use a different cache store in production.
  # config.cache_store = :mem_cache_store

  # Use a real queuing backend for Active Job (and separate queues per environment)
  # config.active_job.queue_adapter     = :resque
  # config.active_job.queue_name_prefix = "kidsclub_#{Rails.env}"
  config.action_mailer.perform_caching = false

  # Ignore bad email addresses and do not raise email delivery errors.
  # Set this to true and configure the email server for immediate delivery to raise delivery errors.
  # config.action_mailer.raise_delivery_errors = false

  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  # the I18n.default_locale when a translation cannot be found).
  config.i18n.fallbacks = true

  # Send deprecation notices to registered listeners.
  config.active_support.deprecation = :notify

  # Use default logging formatter so that PID and timestamp are not suppressed.
  config.log_formatter = ::Logger::Formatter.new

  # Use a different logger for distributed setups.
  # require 'syslog/logger'
  # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')

  if ENV["RAILS_LOG_TO_STDOUT"].present?
    logger           = ActiveSupport::Logger.new(STDOUT)
    logger.formatter = config.log_formatter
    config.logger = ActiveSupport::TaggedLogging.new(logger)
  end

  # Default url options
  config.action_mailer.default_url_options = {:host => 'https://manage.daviskidsklub.com'}
  config.action_controller.default_url_options = {:host => 'https://manage.daviskidsklub.com'}

  #Mailer asset host
  config.action_mailer.asset_host = "https://manage.daviskidsklub.com"

  ActionMailer::Base.smtp_settings = {
      :port =>           '587',
      :address =>        'smtp.sendgrid.net',
      :user_name =>      ENV['SENDGRID_USERNAME'],
      :password =>       ENV['SENDGRID_PASSWORD'],
      :domain =>         'manage.daviskidsklub.com',
      :authentication => :plain,
      :enable_starttls_auto => true
  }
  ActionMailer::Base.delivery_method = :smtp

  # Do not dump schema after migrations.
  config.active_record.dump_schema_after_migration = false

  config.read_encrypted_secrets = true
end

编辑2:

Shopify/money 初始化文件 (

/config/initializers/shopify_money.rb
):

Money.configure do |config|
  config.default_currency = Money::Currency.new("USD")
end

编辑3:

以防万一这是某种宝石问题,这是我的宝石文件:

source 'https://rubygems.org'

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end

ruby "2.6.6"

gem 'devise', '4.4'
gem 'haml-rails', '~> 2.0'
gem 'wicked', '~> 1.3', '>= 1.3.1'
gem 'forgery', '~> 0.6.0'
gem 'seed-fu', '~> 2.3', '>= 2.3.6'
gem 'awesome_print', '~> 1.7'
gem 'flatpickr_rails'
gem 'pundit', '~> 1.1'
gem "font-awesome-rails"
gem "chronic"
gem 'shopify-money', '~> 1.1'
gem "cocoon"
gem "stamp"
gem "stripe"
gem "kaminari"
gem "roo"
gem "classy_enum"
# Error Reporting
gem "sentry-raven"


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '5.1.1'
# Use sqlite3 as the database for Active Record
gem 'pg'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'jquery-tablesorter'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
gem "clipboard-rails"
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
gem 'bootstrap-sass', '~> 3.3', '>= 3.3.7'

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platform: :mri
  # For easy test records
  gem "factory_girl_rails", "~> 4.8"
  # For generating fake data
  gem "faker", "~> 1.7.3"
  # Test suite
  gem "rspec-rails", "~> 3.6"
end

# Heroku
gem 'rails_12factor', group: [:production, :beta]

group :development do
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '~> 3.0.5'
  # Automatic Ruby code style checking tool
  gem "rubocop", "~> 0.49.1"
  gem "letter_opener"
  gem 'rails_db', '2.0.4'
end

group :test do
  # A gem providing "time travel" and "time freezing" capabilities for tests
  gem "timecop", "~> 0.9.0"
  gem 'rspec-activemodel-mocks'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
heroku deployment ruby-on-rails-5
1个回答
1
投票

对此的早期摇摆。

是的,Rails 有

ActiveJob::Serializers
,我猜它只是 yet
shopify-money
加载时初始化。

我猜它在本地工作,因为

production.rb
有一些
development.rb
没有的东西试图加载这个宝石before
ActiveJob
.

要确认,您可以尝试在本地执行

RAILS_ENV=production rails console
。它应该以同样的方式失败。

至于修复,您的选择是推迟加载 gem 的

JobArgumentSerializer
,直到您确定所有 Rails 都已加载或执行相反的操作,并确保
require "active_job/serializers"
在任何
shopify-money
代码之前。

application.rb
,我希望看到这样的东西:

require "rails" #<- all of Rails, including ActiveJob
...
Bundler.require(*Rails.groups) #<- requires the gems from your Gemfile

这确保所有的宝石都在 Rails 之后加载。

我猜你在初始化器或

production.rb
中有一些东西在加载
application.rb
文件之前尝试使用 gem.


根据评论更新:

我按照你的建议对 development.yml 文件进行了更改,但我得到了同样的错误!

环境之间主要有两个变化:

  1. 您的

    /environments
    文件夹中的代码。

  2. 适合特定环境

    group
    的宝石

因为你的 Gemfile 对我来说没有什么特别之处,而且我在

production.rb
中没有看到任何危险信号(尽管你仍然应该将它与你的
development.rb
文件进行比较以确保)

而且既然你现在可以在本地测试你的生产环境,我会先尝试最简单的事情:

# /config/initializers/shopify_money.rb

## play around with which of these classes are required to avoid the error

# gets you EVERYTHING, avoid if possible:
require "rails/all"

# all of Rails, try for just ActiveJob:
require "rails"

# all of ActiveJob, try for just ActiveJob::Serializers:
require "active_job"

# try only using this one:
require "active_job/serializers"

# probably not the fix, but worth trying:
require "money"

Money.configure do |config|
  config.default_currency = Money::Currency.new("USD")
end
© www.soinside.com 2019 - 2024. All rights reserved.