class Eco::API::UseCases::GraphQL::Samples::Location module Command::Service # Service to generate the command updates. module TreeUpdate # Whether to stop or continue on command fail FORCE_CONTINUE = false class << self def included(base) super(base) base.send :include, Eco::API::UseCases::GraphQL::Samples::Location::Service::TreeDiff base.send :include, Eco::API::UseCases::GraphQL::Samples::Location::Command::DSL base.send :include, Eco::API::UseCases::GraphQL::Utils::Sftp base.send :include, InstanceMethods end end module InstanceMethods def process super ensure rescued { re_archive } rescued { email_digest('TagTree Update') } end # Before closing, run RE-ARCHIVE: those that where unarchived via archivedToken # that should remain archived. # @note this is an additional necessary step def re_archive return if simulate? stage = :rearchive nodes_diff_class.new( hash_list(current_tree), file_nodes_list, original_tree: current_tree, logger: logger ).tap do |nodes_diff| archive_input = input(nodes_diff.stage_commands(:archive), force_continue: true) sliced_batches( archive_input, desc: stage, track_tree_mode: :once ) do |sliced_input, response, page, pages, count, total| # rubocop:disable Metrics/ParameterLists page_results = request_results_class.new(sliced_input, response) (results[stage] ||= []) << page_results self.error ||= page_errors?(page_results, page, pages, count, total, stage: stage) end end end private # Work with adapted diff builders. def nodes_diff_class Eco::API::UseCases::GraphQL::Helpers::Location::Command::Diffs end def inputs(nodes_diff = comparer, force_continue: force_continue?) {}.tap do |sequence| 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 # Generates the file and pushes to the SFTP folder # @note this method can only work if we can run cummulative dry-runs to the back-end. # This is only possible using a draft, which is not that desired. # @note the SFTP push only happens if `remote_subfolder` is defined, via: # 1. `options.dig(:sftp, :remote_subfolder)` # 2. `REMOTE_FOLDER` const def close_handling_tags_remap_csv return false unless super upload(tags_remap_csv_file) unless remote_subfolder.nil? true end def email_digest(title) return if simulate? return if options.dig(:workflow, :no_email) digest_msgs = logger.cache.logs(level: %i[info error warn]) exception = exception ? " - Exception!" : '' subject = "#{config.active_enviro} - #{title}#{exception}" session.mail(subject: subject, body: digest_msgs.join) end def print_diff_details? false end end end end end