Class: Karafka::Pro::Processing::StrategySelector
- Inherits:
-
Object
- Object
- Karafka::Pro::Processing::StrategySelector
- Defined in:
- lib/karafka/pro/processing/strategy_selector.rb
Overview
Selector of appropriate processing strategy matching topic combinations When using Karafka Pro, there is a different set of strategies than for regular, as there are different features.
Constant Summary collapse
- SUPPORTED_FEATURES =
Strategies that we support in the Pro offering They can be combined
%i[ active_job long_running_job manual_offset_management virtual_partitions dead_letter_queue filtering ].freeze
Instance Attribute Summary collapse
-
#strategies ⇒ Object
readonly
Returns the value of attribute strategies.
Instance Method Summary collapse
-
#find(topic) ⇒ Module
Module with proper strategy.
-
#initialize ⇒ StrategySelector
constructor
A new instance of StrategySelector.
Constructor Details
#initialize ⇒ StrategySelector
Returns a new instance of StrategySelector.
34 35 36 37 38 |
# File 'lib/karafka/pro/processing/strategy_selector.rb', line 34 def initialize # Preload the strategies # We load them once for performance reasons not to do too many lookups @strategies = find_all end |
Instance Attribute Details
#strategies ⇒ Object (readonly)
Returns the value of attribute strategies.
21 22 23 |
# File 'lib/karafka/pro/processing/strategy_selector.rb', line 21 def strategies @strategies end |
Instance Method Details
#find(topic) ⇒ Module
Returns module with proper strategy.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/karafka/pro/processing/strategy_selector.rb', line 43 def find(topic) feature_set = SUPPORTED_FEATURES.map do |feature_name| topic.public_send("#{feature_name}?") ? feature_name : nil end feature_set.compact! feature_set.sort! @strategies.find do |strategy| strategy::FEATURES.sort == feature_set end || raise(Errors::StrategyNotFoundError, topic.name) end |