Sha256: eee93cb865eaed07bada56abec23e4ea80079f830f5aa805b44dd414e7b876cd

Contents?: true

Size: 1.2 KB

Versions: 9

Compression:

Stored size: 1.2 KB

Contents

module Ecoportal
  module API
    class V1
      class People

        def job
          operation = Common::BatchOperation.new("/people", person_class, logger: client.logger)
          yield operation
          # The batch operation is responsible for logging the output
          job_id = create_job(operation)
          status = wait_for_job_completion(job_id)

          if status&.complete?
            operation.process_response job_result(job_id, operation)
          else
            raise "Job `#{job_id}` not complete. Probably timeout after #{JOB_TIMEOUT + 120} seconds. Current status: #{status}"
          end
        end

        private

        def wait_for_job_completion(job_id)
          # timeout library is evil. So we make poor-man timeout.
          # https://jvns.ca/blog/2015/11/27/why-rubys-timeout-is-dangerous-and-thread-dot-raise-is-terrifying/
          before = Time.now
          while true
            status = job_status(job_id)
            break status if status.complete?
            break status if Time.now >= before + (JOB_TIMEOUT + 120)
            sleep(DELAY_STATUS_CHECK)
            status
          end
        end

      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
eco-helpers-1.3.15 lib/eco/api/common/version_patches/ecoportal_api/external_people.rb
eco-helpers-1.3.14 lib/eco/api/common/version_patches/ecoportal_api/external_people.rb
eco-helpers-1.3.13 lib/eco/api/common/version_patches/ecoportal_api/external_people.rb
eco-helpers-1.3.12 lib/eco/api/common/version_patches/ecoportal_api/external_people.rb
eco-helpers-1.3.11 lib/eco/api/common/version_patches/ecoportal_api/external_people.rb
eco-helpers-1.3.10 lib/eco/api/common/version_patches/ecoportal_api/external_people.rb
eco-helpers-1.3.9 lib/eco/api/common/version_patches/ecoportal_api/external_people.rb
eco-helpers-1.3.8 lib/eco/api/common/version_patches/ecoportal_api/external_people.rb
eco-helpers-1.3.7 lib/eco/api/common/version_patches/ecoportal_api/external_people.rb