lib/eco/api/session/batch/jobs.rb in eco-helpers-2.0.49 vs lib/eco/api/session/batch/jobs.rb in eco-helpers-2.0.50
- old
+ new
@@ -1,10 +1,12 @@
module Eco
module API
class Session
class Batch
class Jobs < API::Common::Session::BaseSession
+ DELAY_BETWEEN_JOBS = 0.3
+
include Enumerable
attr_reader :name
def initialize(e, name:)
super(e)
@@ -85,15 +87,16 @@
# Launches every `Batch::Job` in the group.
# @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 do |job|
+ 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
end
launch(simulate: simulate) if pending?
return status
end
@@ -123,9 +126,14 @@
[].tap do |msg|
map {|job| msg << job.summary}
end.join("\n")
end
+ private
+
+ def delay_between_jobs
+ config.delay_between_jobs || DELAY_BETWEEN_JOBS
+ end
end
end
end
end
end