0
votes

I have some trouble with Redis pub/sub in RoR on production mode.
I have 3 instance: RoR server, Node server and Rake task and Model in some state (Model state 1)

  1. RoR server updates Model with id = 1 and publish event 'one' to Redis. (Model state 2)

  2. Node.js server subscribed to Redis event 'one' gets message, doing something and publish event 'two' to Redis with some data

  3. Rake task in Rails env subscribed to Redis event 'two' gets message and update Model with message data (Model state 3)

Some time later:

  1. Node.js server publish event 'three' to Redis with Model id.
  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.

It is observed only in the case of production mode. In development mode rake task gets Model state 3 and everything is ok.

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
1

1 Answers

0
votes

Problem solved starting rake task in production mode

bundle exec rake some:task RAILS_ENV=production