mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Support env based config file
This commit is contained in:
parent
27ca38bc7a
commit
86f069cff7
3 changed files with 52 additions and 0 deletions
|
@ -246,6 +246,9 @@ module Sidekiq
|
|||
opts = {}
|
||||
if cli[:config_file] && File.exist?(cli[:config_file])
|
||||
opts = YAML.load(ERB.new(IO.read(cli[:config_file])).result)
|
||||
if env = cli[:environment]
|
||||
opts = opts[env] || opts
|
||||
end
|
||||
parse_queues opts, opts.delete(:queues) || []
|
||||
end
|
||||
opts
|
||||
|
|
10
test/env_based_config.yml
Normal file
10
test/env_based_config.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
staging:
|
||||
:verbose: false
|
||||
:require: ./test/fake_env.rb
|
||||
:pidfile: /tmp/sidekiq-config-test.pid
|
||||
:logfile: /tmp/sidekiq.log
|
||||
:concurrency: 50
|
||||
:queues:
|
||||
- [<%="very_"%>often, 2]
|
||||
- [seldom, 1]
|
|
@ -191,6 +191,45 @@ class TestCli < MiniTest::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
describe 'with env based config file' do
|
||||
before do
|
||||
@cli.parse(['sidekiq', '-e', 'staging', '-C', './test/env_based_config.yml'])
|
||||
end
|
||||
|
||||
it 'takes a path' do
|
||||
assert_equal './test/env_based_config.yml', Sidekiq.options[:config_file]
|
||||
end
|
||||
|
||||
it 'sets verbose' do
|
||||
refute Sidekiq.options[:verbose]
|
||||
end
|
||||
|
||||
it 'sets require file' do
|
||||
assert_equal './test/fake_env.rb', Sidekiq.options[:require]
|
||||
end
|
||||
|
||||
it 'sets environment' do
|
||||
assert_equal 'staging', Sidekiq.options[:environment]
|
||||
end
|
||||
|
||||
it 'sets concurrency' do
|
||||
assert_equal 50, Sidekiq.options[:concurrency]
|
||||
end
|
||||
|
||||
it 'sets pid file' do
|
||||
assert_equal '/tmp/sidekiq-config-test.pid', Sidekiq.options[:pidfile]
|
||||
end
|
||||
|
||||
it 'sets logfile' do
|
||||
assert_equal '/tmp/sidekiq.log', Sidekiq.options[:logfile]
|
||||
end
|
||||
|
||||
it 'sets queues' do
|
||||
assert_equal 2, Sidekiq.options[:queues].count { |q| q == 'very_often' }
|
||||
assert_equal 1, Sidekiq.options[:queues].count { |q| q == 'seldom' }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with config file and flags' do
|
||||
before do
|
||||
# We need an actual file here.
|
||||
|
|
Loading…
Reference in a new issue