Sha256: 120584829f30cf6edf75044aa568605d4f53ff1c0b3a251d5232373d0f60ac83

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

module Eco
  module API
    class Session
      class Batch
        module Launcher
          module Retry
            def self.included(base)
              unless base <= Eco::API::Session::Batch::Launcher
                msg  = "To be included only in Eco::API::Common::Session::BaseSession. "
                msg << "Tried on '#{base}'"
                raise msg
              end

              super
            end

            private

            def offer_retry_on(*error_types, retries_left: 3, &block)
              yield
            rescue *error_types => err
              raise err.class, err.message, cause: nil unless retries_left.positive?

              explanation = "#{err}\n"
              explanation << "You have #{retries_left} retries left."
              question    = " Do you want to retry (y/N)?"

              prompt_user(question, default: "Y", explanation: explanation, timeout: 10) do |response|
                raise unless response.upcase.start_with?("Y")

                puts "\nOkay... let's retry!"
                offer_retry_on(*error_types, retries_left: retries_left - 1, &block)
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
eco-helpers-3.0.19 lib/eco/api/session/batch/launcher/retry.rb
eco-helpers-3.0.18 lib/eco/api/session/batch/launcher/retry.rb