RoR+Node.js Redis sub/pub在生产中



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

  1. RoR服务器更新id为1的Model,并将事件"one"发布到Redis。(型号状态2)

  2. Node.js服务器订阅Redis事件‘one’得到消息,做了一些事情,并用一些数据将事件‘two’发布到Redis

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

一段时间后:

  1. Node.js服务器将事件"three"发布到具有Model id的Redis
  2. 订阅事件"three"的同一rake任务获取消息,并根据接收到的id(model.find_by(id:message[:id]))查找模型,并获取模型状态1,但不获取模型状态3

只有在生产模式的情况下才能观察到。在开发模式下,rake任务得到模型状态3,一切正常

开发.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

生产.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

最新更新