Managing long-running operations with the Deployment Manager API

When you make an API request to Deployment Manager, Deployment Manager makes corresponding requests to other Google Cloud APIs. For example, when you create a deployment that includes a Compute Engine instance, Deployment Manager sends an instances.insert request to the Compute Engine API.

When you are creating, updating, or deleting deployments, or using other API methods that might take several minutes or longer to complete, API requests to Deployment Manager return long-running operations.

This page describes the guidelines for managing long-running operations with the Deployment Manager API.

Before you begin

Methods that might start long-running operations include:

In these requests, the response is an Operation resource, which looks like this example:

{
 "kind": "deploymentmanager#operation",
 "id": "7123423453456654321",  # generated ID
 "name": "operation-11233234311678-587af2c0xyz9c-0987fa54-baccd59f",  # generated name
 "operationType": "insert",
 "targetLink": "https://www.googleapis.com/deploymentmanager/v2/projects/example-project/global/deployments/wordpress-1",
 "targetId": "5123321654456321123",
 "status": "DONE",  # possible values: RUNNING, PENDING, DONE
 "user": "example@example.com",
 "progress": 100,
 "insertTime": "2019-04-29T11:08:32.190-07:00",
 "startTime": "2019-04-29T11:08:32.200-07:00",
 "endTime": "2019-04-29T11:09:38.176-07:00",
 "selfLink": "https://www.googleapis.com/deploymentmanager/v2/projects/example-project/global/operations/operation-11233234311678-587af2c0xyz9c-0987fa54-baccd59f"
}

Get the status of an operation

To check the status of an operation, use the operation's name field to make an operations.get() request, and check the status or progress of the operation.

When the status is DONE, progress is 100, and the error object is empty, your deployment is complete and your resources are ready to use.

If there are errors during the operation, they are listed in the error object, in the following format:

"error": {
  "errors": [
    {
      "code": "error code"  # string,
      "location": "location of the error"  # string,
      "message": "error message"   # string
    },
    ...
  ]
}

As a best practice, we recommend polling the operation's status with an exponential backoff. For example, make the first request after 5 seconds, the next after 10 seconds, the third after 20 seconds, and so on. We recommend setting a maximum backoff time of a few minutes. After you reach the maximum backoff time, you do not need to continue increasing the backoff time.