lib/eco/api/session/batch.rb in eco-helpers-2.0.12 vs lib/eco/api/session/batch.rb in eco-helpers-2.0.13

- old
+ new

@@ -103,25 +103,41 @@ iteration = 1; done = 0 iterations = (data.length.to_f / per_page).ceil Eco::API::Session::Batch::Status.new(enviro, queue: data, method: method).tap do |status| + start_time = Time.now + start_slice = Time.now; slice = [] data.each_slice(per_page) do |slice| - msg = "starting batch '#{method}' iteration #{iteration}/#{iterations}, with #{slice.length} entries of #{data.length} -- #{done} done" + 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)})" logger.info(msg) unless silent + start_slice = Time.now people_api.batch do |batch| slice.each do |person| batch.public_send(method, person) do |response| faltal("Request with no response") unless !!response status[person] = response end end end # next batch - iteration += 1 - done += slice.length + iteration += 1 + done += slice.length end # next slice + end + end + + def str_stats(start, count) + now = Time.now + secs = (now - start).round(3) + if secs > 0.0 + per_sec = (count.to_f / secs).round(2) + "#{secs}s -> #{per_sec} people/s" + else + " -- " end end end end