Sha256: b160096864d3743a3eaf42a15314c8850c58a059567df2093fe465ef96c7fb8d

Contents?: true

Size: 1.93 KB

Versions: 25

Compression:

Stored size: 1.93 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, :exception

    def rescued
      yield
    rescue StandardError => e
      log(:error) { self.exception ||= e.patch_full_message }
    end

    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

25 entries across 25 versions & 1 rubygems

Version Path
eco-helpers-3.0.6 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-3.0.5 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-3.0.4 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-3.0.3 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-3.0.2 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-3.0.1 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-3.0.0 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-2.7.25 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-2.7.24 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-2.7.23 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-2.7.22 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-2.7.21 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-2.7.20 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-2.7.19 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-2.7.18 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-2.7.17 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-2.7.16 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-2.7.15 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-2.7.14 lib/eco/api/usecases/graphql/samples/location/command/results.rb
eco-helpers-2.7.13 lib/eco/api/usecases/graphql/samples/location/command/results.rb