diff --git a/lib/sidekiq/cli.rb b/lib/sidekiq/cli.rb index 8f4e77be..d9e64a2e 100644 --- a/lib/sidekiq/cli.rb +++ b/lib/sidekiq/cli.rb @@ -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 diff --git a/test/env_based_config.yml b/test/env_based_config.yml new file mode 100644 index 00000000..447bbf86 --- /dev/null +++ b/test/env_based_config.yml @@ -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] diff --git a/test/test_cli.rb b/test/test_cli.rb index 1738be03..63f2fe0b 100644 --- a/test/test_cli.rb +++ b/test/test_cli.rb @@ -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.