Long-Running Operations#

Wrap long-running operations returned from Google Cloud APIs.

class google.cloud.operation.Operation(name, client, **caller_metadata)[source]#

Bases: object

Representation of a Google API Long-Running Operation.

This wraps an operation protobuf object and attempts to interact with the long-running operations service (specific to a given API). (Some services also offer a JSON API that maps the same underlying data type.)

Parameters:
  • name (str) – The fully-qualified path naming the operation.
  • client (Client) – The client used to poll for the status of the operation. If the operation was created via JSON/HTTP, the client must own a Connection to send polling requests. If created via protobuf, the client must have a gRPC stub in the _operations_stub attribute.
  • caller_metadata (dict) – caller-assigned metadata about the operation
complete#

Has the operation already completed?

Return type:bool
Returns:True if already completed, else false.
error = None#

Error that resulted from a failed (complete) operation.

Only one of this and response can be populated.

classmethod from_dict(operation, client, **caller_metadata)[source]#

Factory: construct an instance from a dictionary.

Parameters:
  • operation (dict) – Operation as a JSON object.
  • client (Client) – The client used to poll for the status of the operation.
  • caller_metadata (dict) – caller-assigned metadata about the operation
Return type:

Operation

Returns:

new instance, with attributes based on the protobuf.

classmethod from_pb(operation_pb, client, **caller_metadata)[source]#

Factory: construct an instance from a protobuf.

Parameters:
  • operation_pb (Operation) – Protobuf to be parsed.
  • client (object: must provide _operations_stub accessor.) – The client used to poll for the status of the operation.
  • caller_metadata (dict) – caller-assigned metadata about the operation
Return type:

Operation

Returns:

new instance, with attributes based on the protobuf.

metadata = None#

Metadata about the current operation (as a protobuf).

Code that uses operations must register the metadata types (via register_type()) to ensure that the metadata fields can be converted into the correct types.

poll()[source]#

Check if the operation has finished.

Return type:bool
Returns:A boolean indicating if the current operation has completed.
Raises:ValueError if the operation has already completed.
response = None#

Response returned from completed operation.

Only one of this and error can be populated.

target = None#

Instance assocated with the operations: callers may set.

google.cloud.operation.register_type(klass, type_url=None)[source]#

Register a klass as the factory for a given type URL.

Parameters:
  • klass (type) – class to be used as a factory for the given type
  • type_url (str) – (Optional) URL naming the type. If not provided, infers the URL from the type descriptor.
Raises:

ValueError if a registration already exists for the URL.