action_cable_preferences.rb 914 B

123456789101112131415161718192021222324
  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}. Please make sure Redis is available."
  19. warn e.inspect
  20. exit! # rubocop:disable Rails/Exit
  21. end
  22. end