RoR + Node.js Redis子/发布在生产中

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

我在生产模式下在RoR中使用Redis pub / sub遇到一些麻烦。
我有3个实例:RoR服务器,节点服务器以及Rake任务和处于某种状态的模型(模型状态1)

  1. RoR服务器更新ID = 1的模型,并将事件“一”发布到Redis。 (模型状态2)

  2. 订阅Redis事件'one'的Node.js服务器获取消息,执行某些操作,然后将事件'two'发布给Redis,并提供一些数据

  3. 订阅Redis事件'two'的Rails env中的Rake任务获取消息并使用消息数据更新模型(模型状态3)

一段时间之后:

  1. Node.js服务器使用模型ID将事件“三”发布到Redis。
  2. 订阅了事件“三”的相同rake任务获取消息并通过接收到的ID(Model.find_by(id:message [:id]))查找模型,并获得模型状态1,但未获得模型状态3。

仅在生产模式下可以观察到。 在开发模式下,rake任务变为Model状态3,一切正常。

development.rb

Rails.application.configure do
  config.cache_classes = false
  config.eager_load = false
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false
  config.action_mailer.raise_delivery_errors = false
  config.active_support.deprecation = :log
  config.active_record.migration_error = :page_load
  config.assets.debug = true
  config.assets.digest = true
  config.assets.raise_runtime_errors = true
end

production.rb

Rails.application.configure do
  config.cache_classes = true
  config.eager_load = true
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.serve_static_files = true
  config.assets.js_compressor = :uglifier
  config.assets.compile = true
  config.assets.digest = true
  config.log_level = :debug
  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify
  config.log_formatter = ::Logger::Formatter.new
  config.active_record.dump_schema_after_migration = false
end
ruby-on-rails node.js redis production-environment rake-task
1个回答
0
投票

解决了在生产模式下启动rake任务的问题

bundle exec rake some:task RAILS_ENV=production
© www.soinside.com 2019 - 2024. All rights reserved.