From 0fcf70834e76b528bd8adb86d45b1e0d13faf767 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 2 Jul 2025 21:22:31 +0200 Subject: [PATCH] Allow customizing Redis database numbers for caching, background jobs and websocket connections. --- CHANGELOG.md | 2 ++ README.md | 1 - config/cable.yml | 4 ++-- config/environments/development.rb | 2 +- config/environments/production.rb | 2 +- config/initializers/geocoder.rb | 2 +- config/initializers/sidekiq.rb | 4 ++-- 7 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 946eb713..cc04cfd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Fixed - Buttons on the imports page now looks better in both light and dark mode. #1481 +- The PROMETHEUS_EXPORTER_ENABLED environment variable default value is now "false", in quotes. +- The RAILS_CACHE_DB, RAILS_JOB_QUEUE_DB and RAILS_WS_DB environment variables can be used to set the Redis database number for caching, background jobs and websocket connections respectively. Default values are now 0, 1 and 2 respectively. #1420 # [0.29.0] - 2025-07-02 diff --git a/README.md b/README.md index f946478d..789bd889 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # 🌍 Dawarich: Your Self-Hosted Location History Tracker [![Discord](https://dcbadge.limes.pink/api/server/pHsBjpt5J8)](https://discord.gg/pHsBjpt5J8) | [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/H2H3IDYDD) | [![Patreon](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%3Dfreika%26type%3Dpatrons&style=for-the-badge)](https://www.patreon.com/freika) -Donate using crypto: [0x6bAd13667692632f1bF926cA9B421bEe7EaEB8D4](https://etherscan.io/address/0x6bAd13667692632f1bF926cA9B421bEe7EaEB8D4) [![CircleCI](https://circleci.com/gh/Freika/dawarich.svg?style=svg)](https://app.circleci.com/pipelines/github/Freika/dawarich) diff --git a/config/cable.yml b/config/cable.yml index 917fe123..ae88845e 100644 --- a/config/cable.yml +++ b/config/cable.yml @@ -1,11 +1,11 @@ development: adapter: redis - url: <%= "#{ENV.fetch("REDIS_URL")}/2" %> + url: <%= "#{ENV.fetch("REDIS_URL")}/#{ENV.fetch('RAILS_WS_DB', 2)}" %> test: adapter: test production: adapter: redis - url: <%= "#{ENV.fetch("REDIS_URL")}/2" %> + url: <%= "#{ENV.fetch("REDIS_URL")}/#{ENV.fetch('RAILS_WS_DB', 2)}" %> channel_prefix: dawarich_production diff --git a/config/environments/development.rb b/config/environments/development.rb index fadc861a..68c0aeaa 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -26,7 +26,7 @@ Rails.application.configure do # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. - config.cache_store = :redis_cache_store, { url: "#{ENV['REDIS_URL']}/0" } + config.cache_store = :redis_cache_store, { url: "#{ENV['REDIS_URL']}/#{ENV.fetch('RAILS_CACHE_DB', 0)}" } if Rails.root.join('tmp/caching-dev.txt').exist? config.action_controller.perform_caching = true diff --git a/config/environments/production.rb b/config/environments/production.rb index 22b3a3d2..cd8cd778 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -73,7 +73,7 @@ Rails.application.configure do config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info') # Use a different cache store in production. - config.cache_store = :redis_cache_store, { url: "#{ENV['REDIS_URL']}/0" } + config.cache_store = :redis_cache_store, { url: "#{ENV['REDIS_URL']}/#{ENV.fetch('RAILS_CACHE_DB', 0)}" } # Use a real queuing backend for Active Job (and separate queues per environment). config.active_job.queue_adapter = :sidekiq diff --git a/config/initializers/geocoder.rb b/config/initializers/geocoder.rb index 4ddfe9d4..13a8bbdd 100644 --- a/config/initializers/geocoder.rb +++ b/config/initializers/geocoder.rb @@ -4,7 +4,7 @@ settings = { debug_mode: true, timeout: 5, units: :km, - cache: Redis.new(url: "#{ENV['REDIS_URL']}/0"), + cache: Redis.new(url: "#{ENV['REDIS_URL']}/#{ENV.fetch('RAILS_CACHE_DB', 0)}"), always_raise: :all, http_headers: { 'User-Agent' => "Dawarich #{APP_VERSION} (https://dawarich.app)" diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index 49b0c98b..323655e3 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true Sidekiq.configure_server do |config| - config.redis = { url: "#{ENV['REDIS_URL']}/1" } + config.redis = { url: "#{ENV['REDIS_URL']}/#{ENV.fetch('RAILS_JOB_QUEUE_DB', 1)}" } config.logger = Sidekiq::Logger.new($stdout) if ENV['PROMETHEUS_EXPORTER_ENABLED'].to_s == 'true' @@ -24,7 +24,7 @@ Sidekiq.configure_server do |config| end Sidekiq.configure_client do |config| - config.redis = { url: "#{ENV['REDIS_URL']}/1" } + config.redis = { url: "#{ENV['REDIS_URL']}/#{ENV.fetch('RAILS_JOB_QUEUE_DB', 1)}" } end Sidekiq::Queue['reverse_geocoding'].limit = 1 if Sidekiq.server? && DawarichSettings.photon_uses_komoot_io?