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 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

#exceptionObject

Returns the value of attribute exception.



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

def exception
  @exception
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



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
53
54
55
56
57
58
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 28

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



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

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

#rescuedObject



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

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

#resultsObject

Capture results



19
20
21
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 19

def results
  @results ||= {}
end