action_cable_preferences.rb 1.1 KB

1234567891011121314151617181920212223242526272829
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. if ENV['ENABLE_EXPERIMENTAL_MOBILE_FRONTEND'] == 'true'
  3. require 'redis'
  4. require 'hiredis'
  5. # If REDIS_URL is not set, fall back to default port / localhost, to ease configuration
  6. # for simple installations.
  7. redis_url = ENV['REDIS_URL'].presence || 'redis://localhost:6379'
  8. Rails.application.config.action_cable.cable = {
  9. adapter: :redis,
  10. driver: :hiredis,
  11. url: redis_url,
  12. channel_prefix: "zammad_#{Rails.env}",
  13. }
  14. begin
  15. Redis.new(driver: :hiredis, url: redis_url).ping
  16. Rails.logger.info { "ActionCable is using the redis instance at #{redis_url}." }
  17. rescue Redis::CannotConnectError => e
  18. warn "There was an error trying to connect to Redis via #{redis_url}."
  19. if ENV['REDIS_URL'].present?
  20. warn 'Please make sure Redis is available.'
  21. else
  22. warn 'Please provide a Redis instance at localhost:6379 or set REDIS_URL to point to a different location.'
  23. end
  24. warn e.inspect
  25. exit! # rubocop:disable Rails/Exit
  26. end
  27. end