lib/eco/api/session/batch.rb in eco-helpers-3.0.15 vs lib/eco/api/session/batch.rb in eco-helpers-3.0.16
- old
+ new
@@ -162,11 +162,11 @@
# Default way to retrieve options (unless provided)
def options
ASSETS.cli.options
end
- def launch_batch( # rubocop:disable Metrics/AbcSize
+ def launch_batch( # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
data,
method:,
status: nil,
job_mode: true, # rubocop:disable Lint/UnusedMethodArgument
options: self.options,
@@ -183,21 +183,22 @@
queue: data,
method: method
)
status.tap do
- start_time = Time.now
- start_slice = Time.now
-
pending_for_server_error = data.to_a[0..]
+
+ start_time = Time.now
+
data.each_slice(per_page) do |slice|
- msg = "starting batch '#{method}' iteration #{iteration}/#{iterations},"
- msg << " with #{slice.length} entries of #{data.length} -- #{done} done"
- msg << " (last: #{str_stats(start_slice, slice.length)}; total: #{str_stats(start_time, done)})"
+ msg = "starting batch '#{method}' iteration #{iteration}/#{iterations}, "
+ msg << "with #{slice.length} entries of #{data.length} -- #{done} done"
+ msg << (" " * 20)
log(:info) { msg } unless silent
start_slice = Time.now
+
offer_retry_on(Ecoportal::API::Errors::TimeOut) do
people_api.batch(job_mode: job_mode?(options)) do |batch|
slice.each do |person|
batch.public_send(method, person) do |response|
faltal("Request with no response") unless response
@@ -209,12 +210,19 @@
end
end
end # end batch
end
+ done += slice.length
+
+ msg = " ... iteration #{iteration}/#{iterations} done "
+ msg << "in #{str_stats(start_slice, slice.length)} "
+ msg << "(average: #{str_stats(start_time, done)})"
+ msg << (" " * 20)
+ log(:info) { msg } unless silent
+
iteration += 1
- done += slice.length
end # next slice
# temporary working around (due to back-end problems with batch/jobs)
unless pending_for_server_error.empty?
msg = "Going to re-try #{pending_for_server_error.count} due to server errors"
@@ -259,10 +267,10 @@
end
end
def str_stats(start, count)
now = Time.now
- secs = (now - start).round(3)
+ secs = (now - start).round(2)
if secs > 0.0
per_sec = (count.to_f / secs).round(2)
"#{secs}s -> #{per_sec} people/s"
else
" -- "