RoR + Node.js Redis sub/pub 投入生产

RoR + Node.js Redis sub/pub on production

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

  1. RoR 服务器更新 id = 1 的模型并将事件 'one' 发布到 Redis。 (模型状态2)

  2. Node.js 服务器订阅 Redis 事件 'one' 获取消息,做一些事情并发布事件 'two' 到 Redis 和一些数据

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

一段时间后:

  1. Node.js 服务器发布事件 'three' 到具有模型 ID 的 Redis。
  2. 订阅事件的相同 rake 任务 'three' 获取消息并通过接收到的 id (Model.find_by(id: message[:id])) 查找模型并获取模型状态 1,但不是模型状态3.

仅在生产模式下观察到。在开发模式下,rake 任务获得模型状态 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

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

bundle exec rake some:task RAILS_ENV=production