lib/eco/api/session/batch/job.rb in eco-helpers-3.0.19 vs lib/eco/api/session/batch/job.rb in eco-helpers-3.0.20

- old
+ new

@@ -215,10 +215,11 @@ backup_update(req_backup, simulate: simulate) end elsif !pqueue.empty? req_backup = as_update(pqueue, add_feedback: false) backup_update(req_backup) + log(:debug) { "Job ('#{name}':#{type}): going to launch batch against #{pqueue.count} entries" } session.batch.launch(pqueue, method: type).tap do |job_status| @@ -244,32 +245,29 @@ # 1. stats of the changes introduced by the job in the different parts of the person model # 2. if the job is compliant with the batch policy # 3. error messages in case they were errors from the server # @note if `launch` was not invoked, it specifies so # @return [String] the summary - def summary # rubocop:disable Metrics/AbcSize + def summary [].tap do |msg| - if pending? - msg << "PENDING - Batch #{type.to_s.upcase} - job '#{name}' - length: #{@queue.length}" - else - msg << feedback.generate(requests, only_stats: true) + msg << "PENDING Job -------->\n" if pending? + msg << feedback.generate(requests, only_stats: true) - if batch_policy && !batch_policy.compliant?(request_stats) - msg << "Batch Policy Uncompliance:" - msg << batch_policy.uncompliance(request_stats) - end - - msg << status.errors.message if status - msg << subjobs_summary + if batch_policy && !batch_policy.compliant?(request_stats) + msg << 'Batch Policy Uncompliance:' + msg << batch_policy.uncompliance(request_stats) end + + msg << status.errors.message if status + msg << subjobs_summary end.join("\n") end private def subjobs_summary - return "" unless subjobs.count.positive? + return '' unless subjobs.count.positive? [].tap do |msg| subjobs.map {|subjob| msg << subjob.summary} end.join("\n") end @@ -429,11 +427,11 @@ status.queue.each do |entry| next unless status.success?(entry) if type == :create && entry.respond_to?(:id=) - entry.id = status[entry].body["id"].tap do |id| + entry.id = status[entry].body['id'].tap do |id| next unless id.to_s.strip.empty? ref = Eco::API::Session::Batch::Feedback.person_ref(entry) msg = "Entry has been created but API did not return its 'id': #{ref}" @@ -501,12 +499,12 @@ end end # Keep a copy of the requests for future reference def backup_update(requests, simulate: false) - dry_run = simulate ? "_dry_run" : "" + dry_run = simulate ? '_dry_run' : '' dir = config.people.requests_folder - filename = name.split(" ").join("-").gsub(/[=\\\/><,"-]+/, "_") # rubocop:disable Style/RedundantArgument + filename = name.split(' ').join('-').gsub(/[=\\\/><,"-]+/, "_") # rubocop:disable Style/RedundantArgument file = File.join(dir, "#{type}_data_#{filename}#{dry_run}.json") file_manager.save_json(requests, file, :timestamp) end # Adds a job tied to the current job