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

Includes:
Helpers::Location::Command, Results, TrackChangedIds, Service::TreeDiff
Included in:
Eco::API::UseCases::GraphQL::Samples::Location::Command
Defined in:
lib/eco/api/usecases/graphql/samples/location/command/dsl.rb

Constant Summary

Constants included from TrackChangedIds

TrackChangedIds::REMAP_LOC_IDS_FILENAME, TrackChangedIds::REMAP_LOC_IDS_FOLDER

Constants included from Helpers::Location::Command::EndPoints::Optimizations

Helpers::Location::Command::EndPoints::Optimizations::DEFAULT_COMMANDS_PER_PAGE

Constants included from Helpers::Location::Base::TreeTracking

Helpers::Location::Base::TreeTracking::TAGTREE_BACKUP

Constants included from Service::TreeToList::Converter::Discarded

Service::TreeToList::Converter::Discarded::DISCARDED_NODES

Constants included from Service::TreeToList::Converter::NodeAttrMaps

Service::TreeToList::Converter::NodeAttrMaps::NODE_ATTR_MAPS

Constants included from Service::TreeToList::Output

Service::TreeToList::Output::OUT_FILENAME, Service::TreeToList::Output::OUT_FOLDER, Service::TreeToList::Output::OUT_HEADER, Service::TreeToList::Output::OUT_TIME_FORMAT

Instance Attribute Summary

Attributes included from Results

#error

Attributes included from Lib::ErrorHandling

#exception, #exiting

Attributes included from Language::AuxiliarLogger

#logger

Attributes included from TrackChangedIds

#tags_remap_csv_file

Attributes included from Helpers::Location::Base::TreeTracking

#current_tree, #previous_tree

Instance Method Summary collapse

Methods included from Results

#error?, #input_unit_response_class, #page_errors?, #result_errors?, #results, #run_results_class

Methods included from Language::AuxiliarLogger

#log

Methods included from TrackChangedIds

#close_handling_tags_remap_csv, #generate_tags_remap_csv, #tags_remap_class, #tags_remap_csv_full_filename, #tags_remap_table, #timestamp_file, #update_tags_remap_table

Methods included from Helpers::Location::Command

#sliced_batches, #with_sliced_input

Methods included from Helpers::Location::Command::EndPoints

#apply_commands, #create_draft, #delete_draft, #publish_draft

Methods included from Helpers::Location::Command::EndPoints::Optimizations

#commands_payload_without_structure_block, #commands_per_page, #default_tree_tracking_mode, #force_continue?, #scope_commands_block

Methods included from Helpers::Location::Base

#live_tree, #session_live_tree, #tagtree_id, #target_structure_id, #target_structure_id_const

Methods included from Helpers::Location::Base::TreeTracking

#backup_tree, #track_current_tree, #track_current_tree?

Methods included from Service::TreeDiff

#compare, #comparer

Instance Method Details

#batch_tree_track_mode(stage) ⇒ Symbol

Note:
  1. This aims to optimize the time run
  2. Based on update stage, there are differentiated tracking needs
Note:

Available options are:

  • :per_request -> on each request
  • :per_batch -> at the end of each batch / stage (on last page)
  • :once -> only when the script starts to run

Default tree tacking behaviour

Returns:

  • (Symbol)

    the tracking mode



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/eco/api/usecases/graphql/samples/location/command/dsl.rb', line 21

def batch_tree_track_mode(stage)
  case stage
  when :unarchive, :archive
    :once
  when :id, :id_name
    :per_request
  when :insert, :move
    :per_batch
  else
    default_tree_tracking_mode
  end
end

#input(commands, force_continue: force_continue?) ) ⇒ Object

With given the commands, it generates the input of the endpoint mutation.

Parameters:

  • commands (Array<Hash>)


36
37
38
39
40
41
42
43
44
45
46
# File 'lib/eco/api/usecases/graphql/samples/location/command/dsl.rb', line 36

def input(commands, force_continue: force_continue?)
  return unless (commands || []).any?

  results.draft ||= create_draft(current_tree.id).draft

  {
    clientMutationId: '',
    id:               results.draft_id,
    commands:         commands
  }
end

#inputs(nodes_diff = comparer, force_continue: force_continue?) ) ⇒ Object

Note:

this method should be overriden/re-implemented

Examples:

of implementation:

def inputs(command_types, force_continue: force_continue?)
  {}.tap do |sequence|
    command_types.commands do |comms, stage|
      sequence[stage] = input(comms, force_continue: force_continue)
    end
  end.tap do |sequence|
    sequence.each do |stage, input|
      yield(input, stage) if block_given?
    end
  end
end


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/eco/api/usecases/graphql/samples/location/command/dsl.rb', line 61

def inputs(nodes_diff = comparer, force_continue: force_continue?)
  {}.tap do |sequence|
    unless nodes_diff && nodes_diff.respond_to?(:commands)
      msg  = "You should implement this method in your child class.\n"
      msg << "Which should yield the input Hash and the stage or descriptor.\n"
      msg << "Or you should provide the `nodes_diff` object."
      raise Eco::API::UseCases::GraphQL::Base::NotImplementedMethod, msg
    end

    nodes_diff.commands do |comms, stage|
      sequence[stage] = input(comms, force_continue: force_continue)
    end
  end.tap do |sequence|
    sequence.each do |stage, input|
      yield(input, stage) if block_given?
    end
  end
end

Returns:

  • (Boolean)


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

def print_diff_details?
  false
end

#processObject

MAIN PROCESSOR



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
108
109
110
111
112
# File 'lib/eco/api/usecases/graphql/samples/location/command/dsl.rb', line 81

def process
  self.error = false

  with_error_handling do
    super if defined?(super)

    # this may trigger a backup of the tagtree
    self.current_tree ||= live_tree

    inputs(
      force_continue: force_continue?
    ) do |input, stage|
      next unless input

      sliced_batches(
        input,
        desc:            stage,
        track_tree_mode: batch_tree_track_mode(stage),
        &results_tracking_block(stage: stage)
      )

      break if error?
    rescue StandardError => err
      log(:error) { err.patch_full_message }
      raise
    end
  end
ensure
  rescued { rearchive } unless exception
  rescued { delete_or_publish_draft }
  rescued { manage_remaps_table     }
end