-
-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Look for polling strategy inside groups config #417
Conversation
lib/shoryuken/options.rb
Outdated
options[group].to_h.fetch(:polling_strategy, Polling::WeightedRoundRobin) | ||
option_group = group == 'default' ? options : options[:groups][group] | ||
strategy = option_group.to_h.fetch(:polling_strategy, Polling::WeightedRoundRobin) | ||
strategy = "Shoryuken::Polling::#{strategy}".constantize if strategy.is_a?(String) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@atyndall constantize
depends on ActiveSupport
.
Maybe the simplest way of doing it would be:
if strategy == 'StrictPriority'
Polling::StrictPriority
else
Polling::WeightedRoundRobin
end
WDYT?
lib/shoryuken/options.rb
Outdated
option_group = group == 'default' ? options : options[:groups][group] | ||
strategy = option_group.to_h.fetch(:polling_strategy, Polling::WeightedRoundRobin) | ||
strategy = "Shoryuken::Polling::#{strategy}".constantize if strategy.is_a?(String) | ||
strategy | ||
end | ||
|
||
def start_callback |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@atyndall WDYT about adding some test cases?
# options_spec.rb
describe '.polling_strategy' do
context 'when not set' do
specify do
expect(Shoryuken.polling_strategy('default')).to eq Shoryuken::Polling::WeightedRoundRobin
end
end
context 'when set' do
before do
Shoryuken.options[:groups] = {
'group1' => {
polling_strategy: 'StrictPriority'
}
}
end
specify do
expect(Shoryuken.polling_strategy('default')).to eq Shoryuken::Polling::WeightedRoundRobin
expect(Shoryuken.polling_strategy('group1')).to eq Shoryuken::Polling::StrictPriority
end
end
end
@phstc Made changes as you suggested. I also restructured it a bit to ensure that if a user mistypes a string, it errors instead of silently picking the |
@atyndall yay added to master 🍻 I will ship a new release tomorrow including your changes. |
@atyndall 3.1.7 is out with your change 🍻 |
shoryuken broken change for group. ruby-shoryuken/shoryuken#417 but, "default" group is not affected, so change it.
Allows group config to specify polling strategy in the .yml like so;
or like so
Note: this change would be backwards incompatible with the current way of setting strategy described here. I have a version that also preserves that behaviour, but it's more complicated.