module ForemanRhCloud::Async::ExponentialBackoff
Public Instance Methods
attempts_before_next_interval()
click to toggle source
Use each interval once
# File lib/foreman_rh_cloud/async/exponential_backoff.rb, line 8 def attempts_before_next_interval 1 end
done!()
click to toggle source
# File lib/foreman_rh_cloud/async/exponential_backoff.rb, line 21 def done! @done = true end
done?()
click to toggle source
# File lib/foreman_rh_cloud/async/exponential_backoff.rb, line 25 def done? @done end
invoke_external_task()
click to toggle source
# 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_task()
click to toggle source
# File lib/foreman_rh_cloud/async/exponential_backoff.rb, line 36 def poll_external_task try_execute # supress unexpected task output serialization {} end
poll_intervals()
click to toggle source
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.
# 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_execute()
click to toggle source
override this method in the consumng class This is the action that we expect to retry in case of an exception.
# File lib/foreman_rh_cloud/async/exponential_backoff.rb, line 44 def try_execute raise NotImplementedError end
Private Instance Methods
random_interval(base)
click to toggle source
# File lib/foreman_rh_cloud/async/exponential_backoff.rb, line 50 def random_interval(base) Random.new.rand(base..10 * base) end