Skip to content

Commit

Permalink
Merge pull request #255 from ifad/chore/full-redis-config
Browse files Browse the repository at this point in the history
redis: allow full configurability
  • Loading branch information
tagliala authored Sep 13, 2024
2 parents 4b070c7 + 97b5e59 commit bc45baa
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
5 changes: 3 additions & 2 deletions config/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ storage_directory: storage
legacy_purge_days: 2

# Sidekiq configuration settings - which redis to use and namespace
redis_url: <%= ENV.fetch('REDIS_URL', 'redis://localhost:6379/4') %>
redis_namespace: colore
redis:
:url: <%= ENV.fetch('REDIS_URL', 'redis://localhost:6379/4') %>
:namespace: colore

# Conversion processes log
conversion_log: log/converter.log
Expand Down
4 changes: 2 additions & 2 deletions config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
require 'config'

Sidekiq.configure_server do |config|
config.redis = { url: Colore::C_.redis_url, namespace: Colore::C_.redis_namespace }
config.redis = Colore::C_.redis
end

Sidekiq.configure_client do |config|
config.redis = { url: Colore::C_.redis_url, namespace: Colore::C_.redis_namespace }
config.redis = Colore::C_.redis
end
9 changes: 3 additions & 6 deletions lib/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ class C_
attr_accessor :legacy_url_base
# Number of days to keep legacy files before purging
attr_accessor :legacy_purge_days
# Redis connection URL (used by sidekiq)
attr_accessor :redis_url
# Redis namespace (used by sidekiq)
attr_accessor :redis_namespace
# Redis configuration (used by sidekiq)
attr_accessor :redis
# Path to the Heathen conversion log
attr_accessor :conversion_log
# Path to the Error log
Expand Down Expand Up @@ -56,8 +54,7 @@ def self.config
c.storage_directory = yaml['storage_directory']
c.legacy_url_base = yaml['legacy_url_base']
c.legacy_purge_days = yaml['legacy_purge_days'].to_i
c.redis_url = yaml['redis_url']
c.redis_namespace = yaml['redis_namespace']
c.redis = yaml['redis']
c.conversion_log = yaml['conversion_log']
c.error_log = yaml['error_log']

Expand Down
5 changes: 3 additions & 2 deletions spec/fixtures/app.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
storage_directory: foo
redis_url: bar
redis_namespace: <%= ENV.fetch('TEST_REDIS_NAMESPACE', 'foobar') %>
redis:
:url: bar
:namespace: <%= ENV.fetch('TEST_REDIS_NAMESPACE', 'foobar') %>
2 changes: 1 addition & 1 deletion spec/lib/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

it 'reads from environment variables' do
expect(ENV).to receive(:fetch).with('TEST_REDIS_NAMESPACE', 'foobar').and_return('custom')
expect(described_class.config.redis_namespace).to eq 'custom'
expect(described_class.config.redis[:namespace]).to eq 'custom'
end
end

Expand Down

0 comments on commit bc45baa

Please sign in to comment.