Class: Sbmt::Outbox::V2::PollThrottler::Composite
- Inherits:
-
Base
- Object
- DryInteractor
- Base
- Sbmt::Outbox::V2::PollThrottler::Composite
- Defined in:
- lib/sbmt/outbox/v2/poll_throttler/composite.rb
Instance Attribute Summary collapse
-
#throttlers ⇒ Object
readonly
Returns the value of attribute throttlers.
Instance Method Summary collapse
- #call(worker_num, poll_task, task_result) ⇒ Object
-
#initialize(throttlers:) ⇒ Composite
constructor
A new instance of Composite.
Methods inherited from Base
Methods inherited from DryInteractor
Constructor Details
#initialize(throttlers:) ⇒ Composite
Returns a new instance of Composite.
12 13 14 15 16 |
# File 'lib/sbmt/outbox/v2/poll_throttler/composite.rb', line 12 def initialize(throttlers:) super() @throttlers = throttlers end |
Instance Attribute Details
#throttlers ⇒ Object (readonly)
Returns the value of attribute throttlers.
10 11 12 |
# File 'lib/sbmt/outbox/v2/poll_throttler/composite.rb', line 10 def throttlers @throttlers end |
Instance Method Details
#call(worker_num, poll_task, task_result) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sbmt/outbox/v2/poll_throttler/composite.rb', line 18 def call(worker_num, poll_task, task_result) # each throttler delays polling thread by it's own rules # i.e. resulting delay is a sum of each throttler's ones results = @throttlers.map do |t| res = t.call(worker_num, poll_task, task_result) return res if res.success? && res.value! == Sbmt::Outbox::V2::Throttler::SKIP_STATUS return res if res.failure? res end throttled(results) || Success(Sbmt::Outbox::V2::Throttler::NOOP_STATUS) end |