Google Cloud PHP shared dependency, providing functionality useful to all components. Client - Class LongRunningOperation (1.60.1)

Reference documentation and code samples for the Google Cloud PHP shared dependency, providing functionality useful to all components. Client class LongRunningOperation.

Represent and interact with a Long Running Operation.

Namespace

Google \ Cloud \ Core \ LongRunning

Methods

__construct

Parameters
Name Description
connection LongRunningConnectionInterface

An implementation mapping to methods which handle LRO resolution in the service. This object is created by internal classes, and should not be instantiated outside of this context.

name string

The Operation name.

callablesMap array

An collection of form [(string) typeUrl, (callable) callable] providing a function to invoke when an operation completes. The callable Type should correspond to an expected value of operation.metadata.typeUrl.

info array

[optional] The operation info.

name

Return the Operation name.

Example:

$name = $operation->name();
Returns
Type Description
string

done

Check if the Operation is done.

If the Operation state is not available, a service request may be executed by this method.

Example:

if ($operation->done()) {
    echo "The operation is done!";
}
Parameter
Name Description
options array

[optional] Configuration options.

Returns
Type Description
bool

state

Get the state of the Operation.

Return value will be one of LongRunningOperation::STATE_IN_PROGRESS, LongRunningOperation::STATE_SUCCESS or LongRunningOperation::STATE_ERROR.

If the Operation state is not available, a service request may be executed by this method.

Example:

switch ($operation->state()) {
    case LongRunningOperation::STATE_IN_PROGRESS:
        echo "Operation is in progress";
        break;

    case LongRunningOperation::STATE_SUCCESS:
        echo "Operation succeeded";
        break;

    case LongRunningOperation::STATE_ERROR:
        echo "Operation failed";
        break;
}
Parameter
Name Description
options array

[optional] Configuration options.

Returns
Type Description
string

result

Get the Operation result.

The return type of this method is dictated by the type of Operation.

Returns null if the Operation is not yet complete, or if an error occurred.

If the Operation state is not available, a service request may be executed by this method.

Example:

$result = $operation->result();
Parameter
Name Description
options array

[optional] Configuration options.

Returns
Type Description
mixed|null

error

Get the Operation error.

Returns null if the Operation is not yet complete, or if no error occurred.

If the Operation state is not available, a service request may be executed by this method.

Example:

$error = $operation->error();
Parameter
Name Description
options array

[optional] Configuration options.

Returns
Type Description
array|null

info

Get the Operation info.

If the Operation state is not available, a service request may be executed by this method.

Example:

$info = $operation->info();
Parameter
Name Description
options array

[optional] Configuration options.

Returns
Type Description
array [google.longrunning.Operation](https://cloud.google.com/spanner/docs/reference/rpc/google.longrunning#google.longrunning.Operation)

reload

Reload the Operation to check its status.

Example:

$result = $operation->reload();
Parameter
Name Description
options array

[optional] Configuration Options.

Returns
Type Description
array [google.longrunning.Operation](https://cloud.google.com/spanner/docs/reference/rpc/google.longrunning#google.longrunning.Operation)

pollUntilComplete

Reload the operation until it is complete.

The return type of this method is dictated by the type of Operation. If $options.maxPollingDurationSeconds is set, and the poll exceeds the limit, the return will be null.

Example:

$result = $operation->pollUntilComplete();
Parameters
Name Description
options array

Configuration Options

↳ pollingIntervalSeconds float

The polling interval to use, in seconds. Defaults to 1.0.

↳ maxPollingDurationSeconds float

The maximum amount of time to continue polling. Defaults to 0.0.

Returns
Type Description
mixed|null

cancel

Cancel a Long Running Operation.

Example:

$operation->cancel();
Parameter
Name Description
options array

Configuration options.

Returns
Type Description
void

delete

Delete a Long Running Operation.

Example:

$operation->delete();
Parameter
Name Description
options array

Configuration Options.

Returns
Type Description
void

__debugInfo

Constants

WAIT_INTERVAL

Value: 1.0

STATE_IN_PROGRESS

Value: 'inProgress'

STATE_SUCCESS

Value: 'success'

STATE_ERROR

Value: 'error'