Class: Dor::Services::Client::AsyncResult
- Inherits:
-
Object
- Object
- Dor::Services::Client::AsyncResult
- Defined in:
- lib/dor/services/client/async_result.rb
Overview
A helper for monitoring asynchonous jobs
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#complete? ⇒ Boolean
Checks to see if the result is complete.
- #errors ⇒ Object
-
#initialize(url:) ⇒ AsyncResult
constructor
A new instance of AsyncResult.
-
#wait_until_complete(seconds_between_requests: 3.0, timeout_in_seconds: 180, backoff_factor: 2.0, max_seconds_between_requests: 60) ⇒ Object
Polls using exponential backoff, so as not to overrwhelm the server.
Constructor Details
#initialize(url:) ⇒ AsyncResult
Returns a new instance of AsyncResult.
13 14 15 |
# File 'lib/dor/services/client/async_result.rb', line 13 def initialize(url:) @url = url end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
10 11 12 |
# File 'lib/dor/services/client/async_result.rb', line 10 def url @url end |
Instance Method Details
#complete? ⇒ Boolean
Checks to see if the result is complete.
31 32 33 34 |
# File 'lib/dor/services/client/async_result.rb', line 31 def complete? @results = Dor::Services::Client.background_job_results.show(job_id: job_id_from(url: url)) @results[:status] == 'complete' end |
#errors ⇒ Object
36 37 38 |
# File 'lib/dor/services/client/async_result.rb', line 36 def errors @results[:output][:errors] end |
#wait_until_complete(seconds_between_requests: 3.0, timeout_in_seconds: 180, backoff_factor: 2.0, max_seconds_between_requests: 60) ⇒ Object
Polls using exponential backoff, so as not to overrwhelm the server.
22 23 24 25 26 27 28 |
# File 'lib/dor/services/client/async_result.rb', line 22 def wait_until_complete(seconds_between_requests: 3.0, timeout_in_seconds: 180, backoff_factor: 2.0, max_seconds_between_requests: 60) poll_until_complete(seconds_between_requests, timeout_in_seconds, backoff_factor, max_seconds_between_requests) errors.nil? end |