Class: SdrClient::RedesignedClient::JobStatus
- Inherits:
-
Object
- Object
- SdrClient::RedesignedClient::JobStatus
- Defined in:
- lib/sdr_client/redesigned_client/job_status.rb
Overview
Wraps operations waiting for results from jobs
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
- #complete? ⇒ Boolean
- #druid ⇒ Object
- #errors ⇒ Object
-
#initialize(job_id:) ⇒ JobStatus
constructor
A new instance of JobStatus.
-
#wait_until_complete(secs_between_requests: 3.0, timeout_in_secs: 180, backoff_factor: 2.0, max_secs_between_requests: 60) ⇒ Boolean
Polls using exponential backoff, so as not to overrwhelm the server.
Constructor Details
#initialize(job_id:) ⇒ JobStatus
Returns a new instance of JobStatus.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/sdr_client/redesigned_client/job_status.rb', line 11 def initialize(job_id:) @job_id = job_id @result = { status: 'not started', output: { errors: nil, druid: '' } } end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
9 10 11 |
# File 'lib/sdr_client/redesigned_client/job_status.rb', line 9 def result @result end |
Instance Method Details
#complete? ⇒ Boolean
22 23 24 25 |
# File 'lib/sdr_client/redesigned_client/job_status.rb', line 22 def complete? @result = client.get(path: path) @result[:status] == 'complete' end |
#druid ⇒ Object
27 28 29 |
# File 'lib/sdr_client/redesigned_client/job_status.rb', line 27 def druid @result[:output][:druid] end |
#errors ⇒ Object
31 32 33 |
# File 'lib/sdr_client/redesigned_client/job_status.rb', line 31 def errors @result[:output][:errors] end |
#wait_until_complete(secs_between_requests: 3.0, timeout_in_secs: 180, backoff_factor: 2.0, max_secs_between_requests: 60) ⇒ Boolean
Polls using exponential backoff, so as not to overrwhelm the server.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/sdr_client/redesigned_client/job_status.rb', line 40 def wait_until_complete(secs_between_requests: 3.0, # rubocop:disable Metrics/MethodLength timeout_in_secs: 180, backoff_factor: 2.0, max_secs_between_requests: 60) begin Timeout.timeout(timeout_in_secs) do loop do break if complete? yield if block_given? sleep(secs_between_requests) # Exponential backoff, limited to max_secs_between_requests secs_between_requests = [secs_between_requests * backoff_factor, max_secs_between_requests].min end end rescue Timeout::Error @result[:output][:errors] = ["Not complete after #{timeout_in_secs} seconds"] end errors.nil? end |