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

#error?Boolean

Returns:

  • (Boolean)


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

def error?
  !!error
end

#input_unit_response_classObject



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

def input_unit_response_class
  Eco::API::UseCases::GraphQL::Helpers::Location::Command::InputUnitResponse
end

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

Note:

it gives feedback on where an error has occurred.

Errors tracking/logging.

Parameters:

  • input_unit_response (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



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 30

def page_errors?(input_unit_response, page, pages, done, total, stage: nil)
  msg = "Expecting CommandResults object. Given: #{input_unit_response.class}"
  raise msg unless input_unit_response.is_a?(input_unit_response_class)

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

  if (errored = input_unit_response.error?)
    log(:error) {
      msg  = "Error on #{fingerprint}: "
      msg << JSON.pretty_generate(input_unit_response.error_doc)
      msg
    }
  else
    log(:info) {
      "Success on #{fingerprint}: #{done} (of #{total}) commands added!"
    }
  end

  errored
end

#result_errors?Boolean

Returns:

  • (Boolean)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 52

def result_errors?
  errored = false

  if results.error?
    errored = true
    log(:error) {
      msg  = "Error on #{fingerprint}: "
      msg << JSON.pretty_generate(input_unit_response.error_doc)
      msg
    }
  end

  # @todo: intermediate status check on drafts doesn't rely on applied

  #   This is rather to be done at the very end, when publishing the draft.

  if input_unit_response.applied?
    log(:info) {
      "Success on #{fingerprint}: #{done} (of #{total}) commands applied!"
    }
  elsif input_unit_response.errored?
    errored = true
    msg     = "Some command failed on #{fingerprint}:\n"
    msg    << input_unit_response.stats

    unless force_continue?
      first_errored = input_unit_response.first_errored
      msg << "The error(s) - #{first_errored.error_msg}\n"
    end

    log(:error) { msg }
  end

  errored
end

#results(target_tree = nil) ⇒ Object

Capture results



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

def results(target_tree = nil)
  @results ||= run_results_class.new(target_tree)
end

#run_results_classObject



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

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