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::CaseEnv
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_class ⇒ Object
-
#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, #session_live_tree, #tagtree_id, #target_structure_id, #track_current_tree
Methods included from Helpers::Base
#backup, #exit_error, #graphql
Methods included from Helpers::Base::CaseEnv
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
110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 110 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 << .to_csv_row 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.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 41 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
26 27 28 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 26 def results @results ||= {} end |
#tags_remap_class ⇒ Object
21 22 23 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 21 def Eco::API::UseCases::GraphQL::Helpers::Location::TagsRemap end |
#tags_remap_table ⇒ Array<Array>
The maps of tags to be used in batch remap tags
32 33 34 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 32 def @tags_remap_table ||= .new end |
#timestamp_file(filename, enviro_relative: true) ⇒ Object
Makes the file relative to the enviro
124 125 126 127 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 124 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
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 104 105 106 107 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/results.rb', line 75 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_path = prev_node.path.reverse new_path = curr_node.path.reverse curr_parent = curr_node.parent.top? ? nil : curr_node.parent unless curr_parent&.id == parent_id msg = "Node '#{node_id}' was moved under '#{parent_id}', " msg << "but in current structure has parent '#{curr_parent&.id}'" log(:warn) { msg } end << [prev_path, new_path] end end end |