lib/eco/api/session/batch.rb in eco-helpers-1.0.13 vs lib/eco/api/session/batch.rb in eco-helpers-1.0.14

- old
+ new

@@ -43,11 +43,11 @@ def search(data, silent: false, params: {}) params = {per_page: DEFAULT_BATCH_BLOCK}.merge(params) launch(data, method: :get, params: params, silent: silent).tap do |status| - status.type = :search + status.mode = :search entries = status.queue puts "\n" entries.each_with_index do |entry, i| if (i % 10 == 0) @@ -84,22 +84,18 @@ end end private - def new_status(queue, method) - Batch::Status.new(enviro, queue: queue, method: method) - end - def get(params: {}, silent: false) fatal "cannot batch get without api connnection, please provide a valid api connection!" unless people_api = api&.people params = {per_page: DEFAULT_BATCH_BLOCK}.merge(params) client = people_api.client looping = !params.key?(:page) - page = params[:page] || 1 + page = params[:page] || 1 people = []; total_pages = nil cursor_id = nil loop do params.merge!(cursor_id: cursor_id) unless !cursor_id @@ -127,11 +123,11 @@ end def client_get(client, params:, silent: false) response = client.get("/people", params: params) unless response.success? - msg = "Request failed - params: #{params}" + msg = "Request failed - params: #{params}" msg += "\n Error message: - Status #{response.status}: #{response.body}" fatal msg end people = [] response.body["results"].each do |person_hash| @@ -145,46 +141,48 @@ def batch_from(data, method:, params: {}, silent: false) fatal "Invalid batch method: #{method}." if !self.class.valid_method?(method) return nil if !data || !data.is_a?(Enumerable) fatal "cannot batch #{method} without api connnection, please provide a valid api connection!" unless people_api = api&.people - # batch Status - status = new_status(data, method) - # param q does not make sense here, even for GET method params = {per_page: DEFAULT_BATCH_BLOCK}.merge(params) per_page = params[:per_page] || DEFAULT_BATCH_BLOCK iteration = 1; done = 0 iterations = (data.length.to_f / per_page).ceil - data.each_slice(per_page) do |slice| - msg = "starting batch '#{method}' iteration #{iteration}/#{iterations}, with #{slice.length} entries of #{data.length} -- #{done} done" - logger.info(msg) unless silent + Eco::API::Session::Batch::Status.new(enviro, queue: data, method: method).tap do |status| + data.each_slice(per_page) do |slice| + msg = "starting batch '#{method}' iteration #{iteration}/#{iterations}, with #{slice.length} entries of #{data.length} -- #{done} done" + logger.info(msg) unless silent - 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 + 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 - end # next batch + end # next batch - iteration += 1 - done += slice.length - end # next slice + iteration += 1 + done += slice.length + end # next slice - status.errors.print unless silent - return status + status.errors.print unless silent + end end end end end end require_relative 'batch/job' +require_relative 'batch/feedback' +require_relative 'batch/request_stats' +require_relative 'batch/base_policy' +require_relative 'batch/policies' require_relative 'batch/status' require_relative 'batch/errors' require_relative 'batch/jobs' require_relative 'batch/jobs_groups'