Module: Karafka::Pro::Routing::Features::Throttling::Topic
- Defined in:
- lib/karafka/pro/routing/features/throttling/topic.rb
Overview
Topic throttling API extensions
Instance Method Summary collapse
-
#initialize ⇒ Object
This method calls the parent class initializer and then sets up the extra instance variable to nil.
-
#throttle(**args) ⇒ Object
Just an alias for nice API.
- #throttling(limit: Float::INFINITY, interval: 60_000) ⇒ Object
-
#throttling? ⇒ Boolean
Is a given job throttled.
-
#to_h ⇒ Hash
Topic with all its native configuration options plus throttling.
Instance Method Details
#initialize ⇒ Object
This method calls the parent class initializer and then sets up the extra instance variable to nil. The explicit initialization to nil is included as an optimization for Ruby’s object shapes system, which improves memory layout and access performance.
42 43 44 45 |
# File 'lib/karafka/pro/routing/features/throttling/topic.rb', line 42 def initialize(...) super @throttling = nil end |
#throttle(**args) ⇒ Object
Just an alias for nice API
77 78 79 |
# File 'lib/karafka/pro/routing/features/throttling/topic.rb', line 77 def throttle(**args) throttling(**args) end |
#throttling(limit: Float::INFINITY, interval: 60_000) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/karafka/pro/routing/features/throttling/topic.rb', line 49 def throttling( limit: Float::INFINITY, interval: 60_000 ) # Those settings are used for validation @throttling ||= begin config = Config.new( active: limit != Float::INFINITY, limit: limit, interval: interval ) # If someone defined throttling setup, we need to create appropriate filter for it # and inject it via filtering feature if config.active? factory = ->(*) { Pro::Processing::Filters::Throttler.new(limit, interval) } filter(factory) end config end end |
#throttling? ⇒ Boolean
Returns is a given job throttled.
82 83 84 |
# File 'lib/karafka/pro/routing/features/throttling/topic.rb', line 82 def throttling? throttling.active? end |
#to_h ⇒ Hash
Returns topic with all its native configuration options plus throttling.
87 88 89 90 91 |
# File 'lib/karafka/pro/routing/features/throttling/topic.rb', line 87 def to_h super.merge( throttling: throttling.to_h ).freeze end |