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

2exbekwf  于 2023-05-18  发布在  其他
关注(0)|答案(1)|浏览(126)

我正在尝试更新一个旧的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:
为了防止出现某种gem问题,下面是我的Gemfile:

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]

最终编辑:
尽管Chiperific尽了最大的努力,但似乎没有任何效果。我终于有了一个灵感,也许Shopify/Money gem对于我正在使用的Rails版本来说更新得太多了。我把它降到了0.16.0,成功了!由于其他原因,我仍然无法在本地启动和运行生产,但是当我部署到Heroku测试站点时,它工作了!我将在不久的某个时候再次升级Rails,并重新访问新版本的Shopify/Money。

3b6akqbq

3b6akqbq1#

这是一个早期的摇摆。
是的,Rails有ActiveJob::Serializers,我猜当shopify-money被加载时,它还没有被初始化。
我猜它在本地工作,因为production.rb有一些development.rb没有的东西,那就是试图在**ActiveJob之前加载这个gem。
为了确认,您可以尝试在本地执行RAILS_ENV=production rails console。它应该以同样的方式失败。
至于修复,您的选择是推迟加载gem的JobArgumentSerializer,直到您确定所有Rails都已加载,或者相反,确保在任何shopify-money代码之前加载require "active_job/serializers"
application.rb中,我希望看到这样的内容:

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

这确保了所有的gem都在Rails之后加载。
我猜在初始化器或production.rb中有一些东西试图在加载application.rb文件之前使用gem。

根据评论更新:

我按照你的建议对development.yml文件进行了修改,但我得到了同样的错误!
在不同的环境中,有两个主要的变化:
1.在您的/environments文件夹中的代码。
1.宝石是group'd到一个特定的环境
因为你的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

相关问题