mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Load aliases for Psych 4 (included in Ruby 3.1) (#5141)
This commit is contained in:
parent
24fb5d3e50
commit
860c7b1909
3 changed files with 41 additions and 1 deletions
|
@ -382,7 +382,7 @@ module Sidekiq
|
|||
def parse_config(path)
|
||||
erb = ERB.new(File.read(path))
|
||||
erb.filename = File.expand_path(path)
|
||||
opts = YAML.load(erb.result) || {}
|
||||
opts = load_yaml(erb.result) || {}
|
||||
|
||||
if opts.respond_to? :deep_symbolize_keys!
|
||||
opts.deep_symbolize_keys!
|
||||
|
@ -398,6 +398,14 @@ module Sidekiq
|
|||
opts
|
||||
end
|
||||
|
||||
def load_yaml(src)
|
||||
if Psych::VERSION > "4.0"
|
||||
YAML.safe_load(src, permitted_classes: [Symbol], aliases: true)
|
||||
else
|
||||
YAML.load(src)
|
||||
end
|
||||
end
|
||||
|
||||
def parse_queues(opts, queues_and_weights)
|
||||
queues_and_weights.each { |queue_and_weight| parse_queue(opts, *queue_and_weight) }
|
||||
end
|
||||
|
|
12
test/config_with_alias.yml
Normal file
12
test/config_with_alias.yml
Normal file
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
:production: &production
|
||||
:verbose: true
|
||||
:require: ./test/fake_env.rb
|
||||
:concurrency: 50
|
||||
:queues:
|
||||
- [<%="very_"%>often, 2]
|
||||
- [seldom, 1]
|
||||
|
||||
:staging:
|
||||
<<: *production
|
||||
:verbose: false
|
|
@ -198,6 +198,26 @@ describe Sidekiq::CLI do
|
|||
assert_equal 1, Sidekiq.options[:queues].count { |q| q == 'seldom' }
|
||||
end
|
||||
|
||||
it 'accepts environment specific config with alias' do
|
||||
subject.parse(%w[sidekiq -e staging -C ./test/config_with_alias.yml])
|
||||
assert_equal './test/config_with_alias.yml', Sidekiq.options[:config_file]
|
||||
refute Sidekiq.options[:verbose]
|
||||
assert_equal './test/fake_env.rb', Sidekiq.options[:require]
|
||||
assert_equal 'staging', Sidekiq.options[:environment]
|
||||
assert_equal 50, Sidekiq.options[:concurrency]
|
||||
assert_equal 2, Sidekiq.options[:queues].count { |q| q == 'very_often' }
|
||||
assert_equal 1, Sidekiq.options[:queues].count { |q| q == 'seldom' }
|
||||
|
||||
subject.parse(%w[sidekiq -e production -C ./test/config_with_alias.yml])
|
||||
assert_equal './test/config_with_alias.yml', Sidekiq.options[:config_file]
|
||||
assert Sidekiq.options[:verbose]
|
||||
assert_equal './test/fake_env.rb', Sidekiq.options[:require]
|
||||
assert_equal 'production', Sidekiq.options[:environment]
|
||||
assert_equal 50, Sidekiq.options[:concurrency]
|
||||
assert_equal 2, Sidekiq.options[:queues].count { |q| q == 'very_often' }
|
||||
assert_equal 1, Sidekiq.options[:queues].count { |q| q == 'seldom' }
|
||||
end
|
||||
|
||||
it 'exposes ERB expected __FILE__ and __dir__' do
|
||||
given_path = './test/config__FILE__and__dir__.yml'
|
||||
expected_file = File.expand_path(given_path)
|
||||
|
|
Loading…
Add table
Reference in a new issue