class Eco::API::UseCases::GraphQL::Samples::Location module Command::DSL include Eco::API::UseCases::GraphQL::Helpers::Location::Command include Eco::API::UseCases::GraphQL::Samples::Location::Command::TrackChangedIds include Eco::API::UseCases::GraphQL::Samples::Location::Command::Results # @example 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 def inputs(*_args, force_continue: force_continue?, **_kargs, &_block) # rubocop:disable Lint/UnusedMethodArgument msg = "You should implement this method in your child class.\n" msg << "Which should yield the input Hash and the stage or descriptor." raise Eco::API::UseCases::GraphQL::Base::NotImplementedMethod, msg end # Main processor def process # rubocop:disable Metrics/AbcSize self.error = false self.exception = nil 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| results[stage] ||= [] track_mode = batch_tree_track_mode(stage) # yields the result of each batch sliced_batches(input, desc: stage, track_tree_mode: track_mode) do |sliced_input, response, page, pages, done, total| # rubocop:disable Metrics/ParameterLists, Layout/LineLength track_current_tree(response&.structure) results[stage] << (page_results = request_results_class.new(sliced_input, response)) update_tags_remap_table(page_results, stage, current_tree) self.error = page_errors?(page_results, page, pages, done, total, stage: stage) break if error end break if error end rescue SystemStackError puts $! # rubocop:disable Style/SpecialGlobalVars puts caller[0..100] raise rescue StandardError => e log(:error) { self.exception ||= e.patch_full_message } raise ensure rescued { self.tags_remap_csv_file = generate_tags_remap_csv } rescued { close_handling_tags_remap_csv } end end # Default tree tacking behaviour # @note # 1. This aims to optimize the time run # 2. Based on update stage, there are differentiated tracking needs # @return [Symbol] the tracking mode 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 end