Class: Ecoportal::API::V1::Job
- Inherits:
-
Object
- Object
- Ecoportal::API::V1::Job
- Defined in:
- lib/ecoportal/api/v1/job.rb,
lib/ecoportal/api/v1/job/status.rb,
lib/ecoportal/api/v1/job/awaiter.rb,
lib/ecoportal/api/v1/job/awaiter/timer.rb,
lib/ecoportal/api/v1/job/awaiter/status_frequency.rb
Overview
TODO:
add #relaunch
where only pending results are requested.
Defined Under Namespace
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#person_class ⇒ Object
readonly
Returns the value of attribute person_class.
Instance Method Summary collapse
-
#batch(recover: false) {|operation| ... } ⇒ Ecoportal::API::Common::Response
The results of the batch job.
- #created? ⇒ Boolean
-
#initialize(client, person_class:) ⇒ People
constructor
An instance object ready to make people api requests.
-
#new ⇒ Object
Allows to preserve the learned throughput.
- #status(job_id) ⇒ Object
Constructor Details
#initialize(client, person_class:) ⇒ People
Returns an instance object ready to make people api requests.
13 14 15 16 17 |
# File 'lib/ecoportal/api/v1/job.rb', line 13 def initialize(client, person_class:) @client = client @person_class = person_class @created = false end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
9 10 11 |
# File 'lib/ecoportal/api/v1/job.rb', line 9 def client @client end |
#person_class ⇒ Object (readonly)
Returns the value of attribute person_class.
9 10 11 |
# File 'lib/ecoportal/api/v1/job.rb', line 9 def person_class @person_class end |
Instance Method Details
#batch(recover: false) {|operation| ... } ⇒ Ecoportal::API::Common::Response
Returns the results of the batch job.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ecoportal/api/v1/job.rb', line 31 def batch(recover: false) raise_if_already_launched! unless recover @operation ||= Common::BatchOperation.new( '/people', person_class, logger: client.logger ) yield operation unless recover total = operation.count job_id = create(operation, recover: recover) stat = awaiter( job_id: job_id, total: total ).await_completion! job_result(job_id, operation) if stat&.complete?(total) end |
#created? ⇒ Boolean
26 27 28 |
# File 'lib/ecoportal/api/v1/job.rb', line 26 def created? @created end |
#new ⇒ Object
Allows to preserve the learned throughput
20 21 22 23 24 |
# File 'lib/ecoportal/api/v1/job.rb', line 20 def new self.class.new(client, person_class: person_class).tap do |out| out.awaiter = @awaiter end end |
#status(job_id) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ecoportal/api/v1/job.rb', line 52 def status(job_id) response = client.get("/people/job/#{CGI.escape(job_id)}/status") body = response && body_data(response.body) msg = "Status error (#{response.status}) - " msg << "Errors: #{body}" raise msg unless response.success? Status.new(*body.values_at(*%w[id complete errored progress])) end |