Module: Eco::API::UseCases::GraphQL::Samples::Location::Command::Results
- Includes:
- Helpers::Location::Base
- Included in:
- DSL
- Defined in:
- lib/eco/api/usecases/graphql/samples/location/command/results.rb
Overview
Logic to:
- Track-down results and errors
- Create tags remap csv table batch design
Constant Summary
Constants included from Helpers::Location::Base
Helpers::Location::Base::TAGTREE_BACKUP
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#exception ⇒ Object
Returns the value of attribute exception.
-
#tags_remap_csv_file ⇒ Object
Returns the value of attribute tags_remap_csv_file.
Attributes included from Helpers::Location::Base
Attributes included from Helpers::Base
Attributes included from Language::AuxiliarLogger
Instance Method Summary collapse
-
#generate_tags_remap_csv(filename = "cache/remap_tags.csv") ⇒ Object
Generates the final tags remap file.
-
#page_errors?(page_results, page, pages, done, total, stage: nil) ⇒ Boolean
Errors tracking/logging.
- #request_results_class ⇒ Object
- #rescued ⇒ Object
-
#results ⇒ Object
Capture results.
-
#tags_remap_table ⇒ Array<Array>
The maps of tags to be used in batch remap tags.
-
#timestamp_file(filename, enviro_relative: true) ⇒ Object
Makes the file relative to the enviro.
-
#update_tags_remap_table(results, stage) ⇒ Object
Based on commands that succeded, and the batch stage, it tracks the tag remaps that should be batches against existing pages.
Methods included from Helpers::Location::Base
#backup_tree, #live_tree, #tagtree_id, #target_structure_id, #track_current_tree
Methods included from Helpers::Base
#backup, #config, #exit_error, #graphql, #simulate?
Methods included from Language::AuxiliarLogger
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
8 9 10 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 8 def error @error end |
#exception ⇒ Object
Returns the value of attribute exception.
8 9 10 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 8 def exception @exception end |
#tags_remap_csv_file ⇒ Object
Returns the value of attribute tags_remap_csv_file.
9 10 11 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 9 def @tags_remap_csv_file end |
Instance Method Details
#generate_tags_remap_csv(filename = "cache/remap_tags.csv") ⇒ Object
Generates the final tags remap file
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 106 def (filename = "cache/remap_tags.csv") return nil if .empty? (filename).tap do |file| CSV.open(file, 'w') do |csv| csv << ["source_tags", "destination_tags"] .each do |(, )| csv << [.join('|'), .join('|')] end end log(:info) { "Generated file '#{file}'" } end end |
#page_errors?(page_results, page, pages, done, total, stage: nil) ⇒ Boolean
it gives feedback on where an error has occurred.
Errors tracking/logging.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 37 def page_errors?(page_results, page, pages, done, total, stage: nil) raise "Expecting CommandResults object. Given: #{page_results.class}" 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_class ⇒ Object
17 18 19 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 17 def request_results_class Eco::API::UseCases::GraphQL::Helpers::Location::Command::Results end |
#rescued ⇒ Object
11 12 13 14 15 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 11 def rescued yield rescue StandardError => e log(:error) { self.exception ||= e. } end |
#results ⇒ Object
Capture results
22 23 24 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 22 def results @results ||= {} end |
#tags_remap_table ⇒ Array<Array>
The maps of tags to be used in batch remap tags
28 29 30 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 28 def @tags_remap_table ||= [] end |
#timestamp_file(filename, enviro_relative: true) ⇒ Object
Makes the file relative to the enviro
120 121 122 123 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 120 def (filename, enviro_relative: true) filename = session.file_manager.dir.file(filename) if enviro_relative Eco::Data::Files.(filename) end |
#update_tags_remap_table(results, stage) ⇒ Object
- This requires to have available the
current_treelocations structure- Fortunatelly this is being tracked, as it is returned as payload of the response.
- Based on the assumption that the order of the commands (stages) happens like this:
- :unarchive, :id_name, :insert, :move, :archive
- The only update operations that generate tag remaps are
:id(or:id_name) and:move.
Based on commands that succeded, and the batch stage, it tracks the tag remaps that should be batches against existing pages
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 71 def (results, stage) return false if [:unarchive, :archive].include?(stage) raise "Expecting CommandResults object. Given: #{results.class}" unless results.is_a?(request_results_class) results.applied.each do |result| case stage when :id, :id_name prev_id, curr_id = result.command_input_data.values_at(:nodeId, :newId) unless current_tree.tag?(curr_id) msg = "Node '#{prev_id}' was updated to '#{curr_id}', " msg << "but in current structure '#{curr_id}' is not present" log(:warn) { msg } end << [[prev_id], [curr_id]] when :move node_id, parent_id = result.command_input_data.values_at(:nodeId, :parentId) prev_node = previous_tree.node(node_id) curr_node = current_tree.node(node_id) = prev_node.path - curr_node.path = curr_node.path - prev_node.path curr_parent = curr_node.parent.top? ? nil : curr_node.parent unless curr_parent&.id == parent_id msg = "Node '#{node_id}' was moved uner '#{parent_id}', " msg << "but in current structure has parent '#{curr_parent&.id}'" log(:warn) { msg } end << [.unshift(node_id), .unshift(node_id)] end end end |