Module: OCI::ContainerEngine::Util

Defined in:
lib/oci/container_engine/util.rb

Overview

Container Engine utility methods

Class Method Summary collapse

Class Method Details

.wait_on_work_request(client, work_request_id, max_interval_seconds: 30, max_wait_seconds: 1200, raise_error_on_failure: true) ⇒ OCI::Response

Wait until the work request succeeds or fails, or max_wait_seconds is reached. The work request will be polled at an increasing rate, with a maximum of max_interval_seconds between requests.

raised if the work request is in a failed state. Similarly, if true, a WorkRequestCanceledError will be raised if the work request is in a canceled state. Models::WorkRequest

Parameters:

  • client (ContainerEngineClient)

    A container engine client

  • the (String)

    work request identifier

  • max_interval_seconds (Integer) (defaults to: 30)

    The maximum interval between queries, in seconds.

  • max_wait_seconds (Integer) (defaults to: 1200)

    The maximum total time to wait, in seconds.

  • raise_error_on_failure (Boolean) (defaults to: true)

    If true, then a WorkRequestFailedError will be

Returns:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/oci/container_engine/util.rb', line 20

def self.wait_on_work_request(client,
                              work_request_id,
                              max_interval_seconds: 30,
                              max_wait_seconds: 1200,
                              raise_error_on_failure: true)
  OCI::Waiter::WorkRequest.wait_for_state(
    client,
    work_request_id,
    ->(work_request) { work_request.status == OCI::ContainerEngine::Models::WorkRequest::STATUS_SUCCEEDED },
    lambda do |work_request|
      is_terminal_state = work_request.status == OCI::ContainerEngine::Models::WorkRequest::STATUS_FAILED
      raise OCI::Errors::WorkRequestFailedError.new(work_request, work_request.status) \
        if raise_error_on_failure && is_terminal_state

      is_terminal_state = work_request.status == OCI::ContainerEngine::Models::WorkRequest::STATUS_CANCELED
      raise OCI::Errors::WorkRequestCanceledError.new(work_request, work_request.status) \
        if raise_error_on_failure && is_terminal_state

      is_terminal_state
    end,
    max_interval_seconds: max_interval_seconds,
    max_wait_seconds: max_wait_seconds
  )
end