class OperationResponse (View source)

Response object from a long running API method.

The OperationResponse object is returned by API methods that perform a long running operation. It provides methods that can be used to poll the status of the operation, retrieve the results, and cancel the operation.

To support a long running operation, the server must implement the Operations API, which is used by the OperationResponse object. If more control is required, it is possible to make calls against the Operations API directly instead of via the OperationResponse object using an OperationsClient instance.

Traits

Constants

DEFAULT_POLLING_INTERVAL

DEFAULT_POLLING_MULTIPLIER

DEFAULT_MAX_POLLING_INTERVAL

DEFAULT_MAX_POLLING_DURATION

Methods

float
getCurrentTimeMillis()

Protected to allow overriding for tests

sleepMillis(float $millis)

Protected to allow overriding for tests

__construct(string $operationName, OperationsClient $operationsClient, array $options = [])

OperationResponse constructor.

bool
isDone()

Check whether the operation has completed.

bool
operationSucceeded()

Check whether the operation completed successfully. If the operation is not complete, or if the operation failed, return false.

bool
operationFailed()

Check whether the operation failed. If the operation is not complete, or if the operation succeeded, return false.

string
getName()

Get the formatted name of the operation

bool
pollUntilComplete(array $options = [])

Poll the server in a loop until the operation is complete.

reload()

Reload the status of the operation with a request to the service.

mixed|null
getResult()

Return the result of the operation. If operationSucceeded() is false, return null.

Status|null
getError()

If the operation failed, return the status. If operationFailed() is false, return null.

array
getDescriptorOptions()

Get an array containing the values of 'operationReturnType', 'metadataReturnType', and the polling options initialPollDelayMillis, pollDelayMultiplier, maxPollDelayMillis, and totalPollTimeoutMillis. The array can be passed as the $options argument to the constructor when creating another OperationResponse object.

Operation|null
getLastProtoResponse()

No description

OperationsClient
getOperationsClient()

No description

cancel()

Starts asynchronous cancellation on a long-running operation. The server makes a best effort to cancel the operation, but success is not guaranteed. If the server doesn't support this method, it will throw an ApiException with code \Google\Rpc\Code::UNIMPLEMENTED. Clients can continue to use reload and pollUntilComplete methods to check whether the cancellation succeeded or whether the operation completed despite cancellation.

delete()

Delete the long-running operation. This method indicates that the client is no longer interested in the operation result. It does not cancel the operation.

mixed
getMetadata()

Get the metadata returned with the last proto response. If a metadata type was provided, then the return value will be of that type - otherwise, the return value will be of type Any. If no metadata object is available, returns null.

Details

protected float getCurrentTimeMillis()

Protected to allow overriding for tests

Return Value

float Current time in milliseconds

protected sleepMillis(float $millis)

Protected to allow overriding for tests

Parameters

float $millis

__construct(string $operationName, OperationsClient $operationsClient, array $options = [])

OperationResponse constructor.

Parameters

string $operationName
OperationsClient $operationsClient
array $options { Optional. Options for configuring the Operation response object.

@type string $operationReturnType The return type of the longrunning operation.
@type string $metadataReturnType The type of the metadata returned in the Operation response.
@type int $initialPollDelayMillis    The initial polling interval to use, in milliseconds.
@type int $pollDelayMultiplier Multiplier applied to the polling interval on each retry.
@type int $maxPollDelayMillis The maximum polling interval to use, in milliseconds.
@type int $totalPollTimeoutMillis The maximum amount of time to continue polling.
@type Operation $lastProtoResponse A response already received from the server.

}

bool isDone()

Check whether the operation has completed.

Return Value

bool

bool operationSucceeded()

Check whether the operation completed successfully. If the operation is not complete, or if the operation failed, return false.

Return Value

bool

bool operationFailed()

Check whether the operation failed. If the operation is not complete, or if the operation succeeded, return false.

Return Value

bool

string getName()

Get the formatted name of the operation

Return Value

string The formatted name of the operation

bool pollUntilComplete(array $options = [])

Poll the server in a loop until the operation is complete.

Return true if the operation completed, otherwise return false. If the $options['totalPollTimeoutMillis'] setting is not set (or set <= 0) then pollUntilComplete will continue polling until the operation completes, and therefore will always return true.

Parameters

array $options { Options for configuring the polling behaviour.

@type int $initialPollDelayMillis The initial polling interval to use, in milliseconds.
@type int $pollDelayMultiplier    Multiplier applied to the polling interval on each retry.
@type int $maxPollDelayMillis     The maximum polling interval to use, in milliseconds.
@type int $totalPollTimeoutMillis The maximum amount of time to continue polling, in milliseconds.

}

Return Value

bool Indicates if the operation completed.

Exceptions

ApiException If an API call fails.
ValidationException

reload()

Reload the status of the operation with a request to the service.

Exceptions

ApiException If the API call fails.
ValidationException If called on a deleted operation.

mixed|null getResult()

Return the result of the operation. If operationSucceeded() is false, return null.

Return Value

mixed|null The result of the operation, or null if operationSucceeded() is false

Status|null getError()

If the operation failed, return the status. If operationFailed() is false, return null.

Return Value

Status|null The status of the operation in case of failure, or null if operationFailed() is false.

array getDescriptorOptions()

Get an array containing the values of 'operationReturnType', 'metadataReturnType', and the polling options initialPollDelayMillis, pollDelayMultiplier, maxPollDelayMillis, and totalPollTimeoutMillis. The array can be passed as the $options argument to the constructor when creating another OperationResponse object.

Return Value

array

Operation|null getLastProtoResponse()

Return Value

Operation|null The last Operation object received from the server.

OperationsClient getOperationsClient()

Return Value

OperationsClient The OperationsClient object used to make requests to the operations API.

cancel()

Starts asynchronous cancellation on a long-running operation. The server makes a best effort to cancel the operation, but success is not guaranteed. If the server doesn't support this method, it will throw an ApiException with code \Google\Rpc\Code::UNIMPLEMENTED. Clients can continue to use reload and pollUntilComplete methods to check whether the cancellation succeeded or whether the operation completed despite cancellation.

On successful cancellation, the operation is not deleted; instead, it becomes an operation with a getError() value with a \Google\Rpc\Status code of 1, corresponding to \Google\Rpc\Code::CANCELLED.

Exceptions

ApiException If the API call fails.

delete()

Delete the long-running operation. This method indicates that the client is no longer interested in the operation result. It does not cancel the operation.

If the server doesn't support this method, it will throw an ApiException with code \Google\Rpc\Code::UNIMPLEMENTED.

Exceptions

ApiException If the API call fails.

mixed getMetadata()

Get the metadata returned with the last proto response. If a metadata type was provided, then the return value will be of that type - otherwise, the return value will be of type Any. If no metadata object is available, returns null.

Return Value

mixed The metadata returned from the server in the last response.