lib/eco/api/session/batch/jobs.rb in eco-helpers-2.7.12 vs lib/eco/api/session/batch/jobs.rb in eco-helpers-2.7.13

- old
+ new

@@ -22,11 +22,11 @@ def length count end def empty? - count == 0 + count.zero? end def each(&block) return to_enum(:each) unless block items.each(&block) @@ -88,19 +88,20 @@ # @note # - if there was post-launch callback for a `Batch::Job`, it calls it. # @return [Hash<Eco::API::Session::Batch::Job, Eco::API::Session::Batch::Status>] def launch(simulate: false) each_with_index do |job, idx| - if job.pending? - status[job] = job_status = job.launch(simulate: simulate) - callback = @callbacks[job] - callback.call(job, job_status) if callback - Eco::API::Session::Batch::JobsGroups.counter(delay_between_jobs) if !simulate && idx < self.length - 1 - end + next unless job.pending? + + status[job] = job_status = job.launch(simulate: simulate) + callback = @callbacks[job] + callback&.call(job, job_status) + Eco::API::Session::Batch::JobsGroups.counter(delay_between_jobs) if !simulate && idx < length - 1 end launch(simulate: simulate) if pending? - return status + + status end def find_jobs(type:) each_with_object([]) do |job, jbs| jbs.push(job) if job.type == type @@ -111,10 +112,10 @@ if block_given? status.each do |job, job_status| yield(job, job_status) end self - else + else # rubocop:disable Naming/MemoizedInstanceVariableName @jobs_status ||= {} end end def errors?