Class: FolioClient::JobStatus
- Inherits:
-
Object
- Object
- FolioClient::JobStatus
- Defined in:
- lib/folio_client/job_status.rb
Overview
Wraps operations waiting for results from jobs
Instance Attribute Summary collapse
-
#job_execution_id ⇒ Object
readonly
Returns the value of attribute job_execution_id.
Instance Method Summary collapse
-
#initialize(job_execution_id:) ⇒ JobStatus
constructor
A new instance of JobStatus.
-
#instance_hrids ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#status ⇒ Dry::Monads::Result
Success() if job is complete, Failure(:pending) if job is still running, Failure(:not_found) if job is not found.
- #wait_until_complete(wait_secs: default_wait_secs, timeout_secs: default_timeout_secs, max_checks: default_max_checks) ⇒ Object
Constructor Details
#initialize(job_execution_id:) ⇒ JobStatus
Returns a new instance of JobStatus.
14 15 16 |
# File 'lib/folio_client/job_status.rb', line 14 def initialize(job_execution_id:) @job_execution_id = job_execution_id end |
Instance Attribute Details
#job_execution_id ⇒ Object (readonly)
Returns the value of attribute job_execution_id.
11 12 13 |
# File 'lib/folio_client/job_status.rb', line 11 def job_execution_id @job_execution_id end |
Instance Method Details
#instance_hrids ⇒ Object
rubocop:disable Metrics/AbcSize
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/folio_client/job_status.rb', line 42 def instance_hrids current_status = status return current_status unless current_status.success? @instance_hrids ||= wait_with_timeout do response = client .get("/metadata-provider/journalRecords/#{job_execution_id}") .fetch('journalRecords', []) .select { |journal_record| journal_record['entityType'] == 'INSTANCE' && journal_record['actionStatus'] == 'COMPLETED' } .filter_map { |instance_record| instance_record['entityHrId'] } response.empty? ? Failure() : Success(response) end end |
#status ⇒ Dry::Monads::Result
TODO:
An “ERROR” approach means one or more records failed, but it does not mean they all fail. We will likely need a more nuanced way to handle this eventually.
Returns Success() if job is complete, Failure(:pending) if job is still running, Failure(:not_found) if job is not found.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/folio_client/job_status.rb', line 25 def status response_hash = client.get("/change-manager/jobExecutions/#{job_execution_id}") return Failure(:pending) unless %w[COMMITTED ERROR].include?(response_hash['status']) Success() rescue ResourceNotFound # Checking the status immediately after starting the import may result in a 404. Failure(:not_found) end |
#wait_until_complete(wait_secs: default_wait_secs, timeout_secs: default_timeout_secs, max_checks: default_max_checks) ⇒ Object
36 37 38 39 |
# File 'lib/folio_client/job_status.rb', line 36 def wait_until_complete(wait_secs: default_wait_secs, timeout_secs: default_timeout_secs, max_checks: default_max_checks) wait_with_timeout(wait_secs: wait_secs, timeout_secs: timeout_secs, max_checks: max_checks) { status } end |