Sha256: 2cc589945c34b90fc97a79443280e54d12b73d14e5c1d3cbbaa71a3a7f9d35d8

Contents?: true

Size: 1.23 KB

Versions: 29

Compression:

Stored size: 1.23 KB

Contents

module ForemanRhCloud
  module Async
    module ExponentialBackoff
      extend ActiveSupport::Concern
      include Dynflow::Action::Polling

      # Use each interval once
      def attempts_before_next_interval
        1
      end

      # 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.
      def poll_intervals
        (1..poll_max_retries).map do |i|
          base = 10**i
          random_interval(base)
        end
      end

      def done!
        @done = true
      end

      def done?
        @done
      end

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

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

      # override this method in the consumng class
      # This is the action that we expect to retry in case of an exception.
      def try_execute
        raise NotImplementedError
      end

      private

      def random_interval(base)
        Random.new.rand(base..10 * base)
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
foreman_rh_cloud-10.0.3 lib/foreman_rh_cloud/async/exponential_backoff.rb
foreman_rh_cloud-11.0.3 lib/foreman_rh_cloud/async/exponential_backoff.rb
foreman_rh_cloud-9.0.59 lib/foreman_rh_cloud/async/exponential_backoff.rb
foreman_rh_cloud-11.0.2 lib/foreman_rh_cloud/async/exponential_backoff.rb
foreman_rh_cloud-11.0.1 lib/foreman_rh_cloud/async/exponential_backoff.rb
foreman_rh_cloud-11.0.0 lib/foreman_rh_cloud/async/exponential_backoff.rb
foreman_rh_cloud-9.0.58 lib/foreman_rh_cloud/async/exponential_backoff.rb
foreman_rh_cloud-10.0.2 lib/foreman_rh_cloud/async/exponential_backoff.rb
foreman_rh_cloud-9.0.57 lib/foreman_rh_cloud/async/exponential_backoff.rb
foreman_rh_cloud-10.0.1 lib/foreman_rh_cloud/async/exponential_backoff.rb
foreman_rh_cloud-9.0.56 lib/foreman_rh_cloud/async/exponential_backoff.rb
foreman_rh_cloud-9.0.55 lib/foreman_rh_cloud/async/exponential_backoff.rb
foreman_rh_cloud-9.0.54 lib/foreman_rh_cloud/async/exponential_backoff.rb
foreman_rh_cloud-9.0.53 lib/foreman_rh_cloud/async/exponential_backoff.rb
foreman_rh_cloud-9.0.52 lib/foreman_rh_cloud/async/exponential_backoff.rb
foreman_rh_cloud-8.0.52 lib/foreman_rh_cloud/async/exponential_backoff.rb
foreman_rh_cloud-9.0.51 lib/foreman_rh_cloud/async/exponential_backoff.rb
foreman_rh_cloud-8.0.51 lib/foreman_rh_cloud/async/exponential_backoff.rb
foreman_rh_cloud-7.0.48 lib/foreman_rh_cloud/async/exponential_backoff.rb
foreman_rh_cloud-7.0.47 lib/foreman_rh_cloud/async/exponential_backoff.rb