Module: Eco::API::UseCases::GraphQL::Samples::Location::Command::Results

Includes:
Helpers::Base::CaseEnv
Included in:
DSL
Defined in:
lib/eco/api/usecases/graphql/samples/location/command/results.rb

Overview

Logic to: Track-down results and errors

Instance Attribute Summary collapse

Attributes included from Helpers::Base::ErrorHandling

#exception, #exiting

Attributes included from Language::AuxiliarLogger

#logger

Instance Method Summary collapse

Methods included from Language::AuxiliarLogger

#log

Instance Attribute Details

#errorObject

Returns the value of attribute error.



6
7
8
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 6

def error
  @error
end

Instance Method Details

#page_errors?(page_results, page, pages, done, total, stage: nil) ⇒ Boolean

Note:

it gives feedback on where an error has occurred.

Errors tracking/logging.

Parameters:

  • page_results (Eco::API::UseCases::GraphQL::Helpers::Locations::Commands::CommandResults)
  • stage (Symbol) (defaults to: nil)

    used when we launch an update in different phases (i.e. rename, move, etc.)

Returns:

  • (Boolean)

    whether or not there was an error



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 22

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

#request_results_classObject



8
9
10
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 8

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

#resultsObject

Capture results



13
14
15
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 13

def results
  @results ||= {}
end