Sha256: b15576e311d9b5d3716faffaa9c923d3c08a992114a38362f0c1770987bf6f76

Contents?: true

Size: 1.79 KB

Versions: 15

Compression:

Stored size: 1.79 KB

Contents

class Eco::API::UseCases::GraphQL::Samples::Location
  # Logic to: Track-down results and errors
  module Command::Results
    include Eco::API::UseCases::GraphQL::Helpers::Base::CaseEnv

    attr_accessor :error

    def request_results_class
      Eco::API::UseCases::GraphQL::Helpers::Location::Command::Results
    end

    # Capture results
    def results
      @results ||= {}
    end

    # Errors tracking/logging.
    # @note it gives feedback on where an error has occurred.
    # @param page_results [Eco::API::UseCases::GraphQL::Helpers::Locations::Commands::CommandResults]
    # @param stage [Symbol] used when we launch an update in different phases (i.e. rename, move, etc.)
    # @return [Boolean] whether or not there was an error
    def page_errors?(page_results, page, pages, done, total, stage: nil)
      msg = "Expecting CommandResults object. Given: #{page_results.class}"
      raise msg unless page_results.is_a?(request_results_class)

      stage_str   = stage ? "'#{stage}' " : ''
      fingerprint = "#{stage_str}#{page} (of #{pages})"
      errored     = false

      if page_results.error?
        errored = true
        log(:error) {
          "Error on #{fingerprint}: #{page_results.error.doc.pretty_inspect}"
        }
      end

      if page_results.applied?
        log(:info) {
          "Success on #{fingerprint}: #{done} (of #{total}) commands applied!"
        }
      elsif page_results.errored?
        errored = true
        msg     = "Some command failed on #{fingerprint}:\n#{page_results.stats}"
        unless force_continue?
          first_errored = page_results.first_errored
          msg << "The error(s) - #{first_errored.error_msg}\n"
        end
        log(:error) { msg }
      end

      errored
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
eco-helpers-3.0.21 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-3.0.20 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-3.0.19 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-3.0.18 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-3.0.17 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-3.0.16 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-3.0.15 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-3.0.14 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-3.0.13 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-3.0.12 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-3.0.11 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-3.0.10 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-3.0.9 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-3.0.8 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-3.0.7 lib/eco/api/usecases/graphql/samples/location/command/results.rb