Class: Sbmt::Outbox::V2::PollThrottler::Composite

Inherits:
Base show all
Defined in:
lib/sbmt/outbox/v2/poll_throttler/composite.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#wait

Methods inherited from DryInteractor

call

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

#throttlersObject (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