简体   繁体   English

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

[英]RoR + Node.js Redis sub/pub on production

I have some trouble with Redis pub/sub in RoR on production mode. 我在生产模式下在RoR中使用Redis pub / sub遇到一些麻烦。
I have 3 instance: RoR server, Node server and Rake task and Model in some state (Model state 1) 我有3个实例:RoR服务器,节点服务器以及Rake任务和处于某种状态的模型(模型状态1)

  1. RoR server updates Model with id = 1 and publish event 'one' to Redis. RoR服务器更新ID = 1的模型,并将事件“一”发布到Redis。 (Model state 2) (模型状态2)

  2. Node.js server subscribed to Redis event 'one' gets message, doing something and publish event 'two' to Redis with some data 订阅Redis事件'one'的Node.js服务器获取消息,执行某些操作,然后将事件'two'发布给Redis,并提供一些数据

  3. Rake task in Rails env subscribed to Redis event 'two' gets message and update Model with message data (Model state 3) 订阅Redis事件'two'的Rails env中的Rake任务获取消息并使用消息数据更新模型(模型状态3)

Some time later: 一段时间之后:

  1. Node.js server publish event 'three' to Redis with Model id. Node.js服务器使用模型ID将事件“三”发布到Redis。
  2. Same rake task subscribed to event 'three' gets message and find model by received id (Model.find_by(id: message[:id])) and gets Model state 1, but not Model state 3. 订阅了事件“三”的相同rake任务获取消息并通过接收到的ID(Model.find_by(id:message [:id]))查找模型,并获得模型状态1,但未获得模型状态3。

It is observed only in the case of production mode. 仅在生产模式下可以观察到。 In development mode rake task gets Model state 3 and everything is ok. 在开发模式下,rake任务变为Model状态3,一切正常。

development.rb 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 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM