# Use case to update a target oozes # @note # - `target_ids` => Expects options[:source][:file] where at least the 1st column should be the target entry `ids` class Eco::API::UseCases::OozeSamples::TargetOozesUpdateCase < Eco::API::UseCases::OozeSamples::RegisterUpdateCase name "target-oozes-update-case" type :other private def with_each_entry batched_target_ids do |ids| ids.each do |id| if (pending = queue_shift(id)) && dirty?(pending) msg = "Same entry 'id' appears more than once. " msg << "Launching update on '#{object_reference(pending)}' to be able to queue it back" console.warn msg update_ooze(pending) end if (ooz = ooze(id)) @retrieved_oozes += 1 yield(ooz) else @non_retrieved_oozes += 1 log(:warn) { "Could not get page #{id}" } end end update_oozes end end def batched_target_ids raise "Missing block. It yields in slices of #{self.class.batch_size} ids" unless block_given? target_ids_preview pool = [] target_ids.each do |id| pool << id if pool.length >= self.class.batch_size yield(pool) pool = [] end end yield(pool) unless pool.empty? end def target_ids_preview dups = target_ids.select {|id| target_ids.count(id) > 1} @total_search_oozes = target_ids.count @dupped_search_oozes = dups.count dups_str = dups.count.positive? ? "There are #{dups.count} duplicated ids" : "No duplicates detected" msg = "Total target entries: #{target_ids.count} (#{dups_str})" default_answer = session.config.run_mode_remote?? "Y" : "N" session.prompt_user( "Do you want to proceed (y/N):", explanation: msg, default: default_answer, timeout: 10 ) do |res| unless res.upcase.start_with?("Y") puts "..." log(:info) { "Aborting script..." } exit(0) end end end def target_ids @target_ids ||= input_csv.columns.first[1..] end def input_csv @input_csv ||= Eco::CSV.read(options.dig(:source, :file)) end end