Module: ForemanRhCloud::Async::ExponentialBackoff

Extended by:
ActiveSupport::Concern
Includes:
Dynflow::Action::Polling
Included in:
ForemanInventoryUpload::Async::ShellProcess, InsightsCloud::Async::InsightsFullSync, InsightsCloud::Async::InsightsResolutionsSync, InsightsCloud::Async::InsightsRulesSync, InventorySync::Async::QueryInventoryJob
Defined in:
lib/foreman_rh_cloud/async/exponential_backoff.rb

Instance Method Summary collapse

Instance Method Details

#attempts_before_next_intervalObject

Use each interval once



8
9
10
# File 'lib/foreman_rh_cloud/async/exponential_backoff.rb', line 8

def attempts_before_next_interval
  1
end

#done!Object



21
22
23
# File 'lib/foreman_rh_cloud/async/exponential_backoff.rb', line 21

def done!
  @done = true
end

#done?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/foreman_rh_cloud/async/exponential_backoff.rb', line 25

def done?
  @done
end

#invoke_external_taskObject



29
30
31
32
33
34
# File 'lib/foreman_rh_cloud/async/exponential_backoff.rb', line 29

def invoke_external_task
  # Call the polling method from task's framework
  poll_external_task_with_rescue
  # supress unexpected task output serialization
  {}
end

#poll_external_taskObject



36
37
38
39
40
# File 'lib/foreman_rh_cloud/async/exponential_backoff.rb', line 36

def poll_external_task
  try_execute
  # supress unexpected task output serialization
  {}
end

#poll_intervalsObject

define poll intervals in the following way: [1/10..1, 1..10, 10..100] e.t.c. total count of intervals would be the amount of poll retries.



14
15
16
17
18
19
# File 'lib/foreman_rh_cloud/async/exponential_backoff.rb', line 14

def poll_intervals
  (1..poll_max_retries).map do |i|
    base = 10**i
    random_interval(base)
  end
end

#try_executeObject

override this method in the consumng class This is the action that we expect to retry in case of an exception.

Raises:

  • (NotImplementedError)


44
45
46
# File 'lib/foreman_rh_cloud/async/exponential_backoff.rb', line 44

def try_execute
  raise NotImplementedError
end