Sha256: 7537e1c35c8455f86ad5e69fe4e119edad4f225499d7c2c36b132751f3aa1c2a

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 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.21 lib/eco/api/session/batch/launcher/retry.rb
eco-helpers-3.0.20 lib/eco/api/session/batch/launcher/retry.rb