Copied!

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 Operations Client instance.

CloneableInstantiable
Constants
public Google\ApiCore\OperationResponse::DEFAULT_MAX_POLLING_DURATION = 0
public Google\ApiCore\OperationResponse::DEFAULT_MAX_POLLING_INTERVAL = 60000
public Google\ApiCore\OperationResponse::DEFAULT_POLLING_INTERVAL = 1000
public Google\ApiCore\OperationResponse::DEFAULT_POLLING_MULTIPLIER = 2
Methods
public __construct(string $operationName, $operationsClient, array $options = [])
 

OperationResponse constructor.

  • param string $operationName
  • param object $operationsClient
  • param 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 object $lastProtoResponse A response already received from the server.
    @type string $getOperationMethod The method on $operationsClient to get the operation.
    @type string $cancelOperationMethod The method on $operationsClient to cancel the operation.
    @type string $deleteOperationMethod The method on $operationsClient to delete the operation.
    @type string $operationStatusMethod The method on the operation to get the status.
    @type string $operationStatusDoneValue The method on the operation to determine if the status is done.
    @type array $additionalOperationArguments Additional arguments to pass to $operationsClient methods.
    @type string $operationErrorCodeMethod The method on the operation to get the error code
    @type string $operationErrorMessageMethod The method on the operation to get the error status
    
    }
public cancel()
 

Cancel the long-running operation.

For operations of type Google\LongRunning\Operation, this method 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.

  • throws \ApiException If the API call fails.
  • throws \LogicException If the API call method has not been configured
public delete()
 

Delete the long-running operation.

For operations of type Google\LongRunning\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.

  • throws \ApiException If the API call fails.
  • throws \LogicException If the API call method has not been configured
public 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 array
public getError()
 

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

  • return \Status|null The status of the operation in case of failure, or null if operationFailed() is false.
public getLastProtoResponse()
 
  • return \Operation|mixed|null The last Operation object received from the server.
public 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 mixed The metadata returned from the server in the last response.
public getName()
 

Get the formatted name of the operation

  • return string The formatted name of the operation
public getOperationsClient()
 
  • return object The OperationsClient object used to make requests to the operations API.
public getResult()
 

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

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

Check whether the operation has completed.

  • return bool
public operationFailed()
 

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

  • return bool
public operationSucceeded()
 

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

  • return bool
public 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.

  • param 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.
    
    }
  • throws \ApiException If an API call fails.
  • throws \ValidationException
  • return bool Indicates if the operation completed.
public reload()
 

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

  • throws \ApiException If the API call fails.
  • throws \ValidationException If called on a deleted operation.
Methods
protected getCurrentTimeMillis()
 

Protected to allow overriding for tests

  • return float Current time in milliseconds
protected sleepMillis(int $millis)
 

Protected to allow overriding for tests

  • param int $millis
Constants
private Google\ApiCore\OperationResponse::NEW_CLIENT_NAMESPACE = '\Client\'
Properties
private array $additionalArgs
private ?string $cancelOperationMethod
private ?string $cancelOperationRequest
private array $defaultPollSettings = ['initialPollDelayMillis' => 1000, 'pollDelayMultiplier' => 2, 'maxPollDelayMillis' => 60000, 'totalPollTimeoutMillis' => 0]
private bool $deleted = false
private ?string $deleteOperationMethod
private ?string $deleteOperationRequest
private string $getOperationMethod
private string $getOperationRequest
private ?object $lastProtoResponse
private ?string $metadataReturnType
private ?string $operationErrorCodeMethod
private ?string $operationErrorMessageMethod
private string $operationName
private ?string $operationReturnType
private ?object $operationsClient
private $operationStatusDoneValue = NULL
 
  • var mixed
private string $operationStatusMethod
Methods
private canHaveResult()
private hasErrors()
private hasProtoResponse()
private isNewSurfaceOperationsClient() : bool
private operationsCall(string $method, ?string $requestClass)
 

Call the operations client to perform an operation.

  • param string $method The method to call on the operations client.
  • param string|null $requestClass The request class to use for the call. Will be null for legacy operations clients.
private poll(callable $pollCallable, array $options)
 
  • param callable $pollCallable The call to poll. Must return a boolean indicating whether the operation has completed, and the polling loop can be terminated.
  • param 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 bool
© 2025 Bruce Wells
Search Namespaces \ Classes
Configuration