本页介绍了如何管理 Financial Services API 长时间运行的操作 (LRO) 的生命周期。
如果方法调用可能需要很长时间才能完成,系统就会返回长时间运行的操作。例如,Financial Services API 会在您每次调用 projects.locations.instances.create 时创建一个 LRO。LRO 会跟踪处理作业的状态。
您可以使用 Financial Services API 提供的 projects.locations.operations 方法来检查 LRO 的状态。您还可以对 LRO 执行 list、cancel 或 delete 操作。
LRO 可在 Google Cloud 项目和位置级层进行管理。向该 API 发出请求时,请在其中提供 Google Cloud 项目以及 LRO 的运行位置。
在 LRO 完成之后,LRO 的记录会保留大约 30 天。在这段时间之后,您将无法再查看或列出 LRO。
获取长时间运行的操作的详细信息
假设您创建了一个实例。响应中的 name 值表明,Financial Services API 创建了一个名为 projects/PROJECT_ID/locations/LOCATION/operations/OPERATION_ID 的 LRO。
使用 projects.locations.operations.get 方法检查实例是否已创建。如果响应包含 "done": false,请重复该命令,直到响应包含 "done": true。此操作可能需要几分钟才能完成。
您还可以通过列出长时间运行的操作来检索 LRO 名称。
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID:IAM 设置中列出的 Google Cloud 项目 IDLOCATION:实例的位置;请使用某个受支持的地区显示位置us-central1us-east1asia-south1europe-west1europe-west2europe-west4northamerica-northeast1southamerica-east1australia-southeast1
OPERATION_ID:操作的标识符
如需发送请求,请选择以下方式之一:
curl
执行以下命令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://financialservices.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/operations/OPERATION_ID"
PowerShell
执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://financialservices.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/operations/OPERATION_ID" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
{
"name": "projects/PROJECT_ID/locations/LOCATION/operations/OPERATION_ID",
"metadata": {
"@type": "type.googleapis.com/google.cloud.financialservices.v1.OperationMetadata",
"createTime": "2023-03-14T15:52:55.358979323Z",
"endTime": "2023-03-14T16:52:55.358979323Z",
"target": "projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID",
"verb": "create",
"requestedCancellation": false,
"apiVersion": "v1"
},
"done": true,
"response": {
"@type": "type.googleapis.com/google.cloud.financialservices.v1.Instance",
"name": "projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID",
"createTime": CREATE_TIME,
"updateTime": UPDATE_TIME,
"state": "ACTIVE",
"kmsKey": "projects/KMS_PROJECT_ID/locations/LOCATION/keyRings/KEY_RING_ID/cryptoKeys/KEY_ID"
}
}
列出长时间运行的操作
使用 projects.locations.operations.list 方法可列出指定位置中的所有操作。
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID:IAM 设置中列出的 Google Cloud 项目 IDLOCATION:操作的位置;请使用某个受支持的地区显示位置us-central1us-east1asia-south1europe-west1europe-west2europe-west4northamerica-northeast1southamerica-east1australia-southeast1
如需发送请求,请选择以下方式之一:
curl
执行以下命令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://financialservices.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/operations"
PowerShell
执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://financialservices.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/operations" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
{
"operations": [
{
"name": "projects/PROJECT_ID/locations/LOCATION/operations/OPERATION_ID",
"metadata": {
"@type": "type.googleapis.com/google.cloud.financialservices.v1.OperationMetadata",
"createTime": "2023-03-14T15:52:55.358979323Z",
"endTime": "2023-03-14T16:52:55.358979323Z",
"target": "projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/engineConfigs/ENGINE_CONFIG_ID",
"verb": "create",
"requestedCancellation": false,
"apiVersion": "v1"
},
"done": false
},
{
"name": "projects/PROJECT_ID/locations/LOCATION/operations/my-other-operation",
"metadata": {
"@type": "type.googleapis.com/google.cloud.financialservices.v1.OperationMetadata",
"createTime": CREATE_TIME,
"endTime": END_TIME,
"target": "projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID",
"verb": "create",
"requestedCancellation": false,
"apiVersion": "v1"
},
"done": true,
"response": {
"@type": "type.googleapis.com/google.cloud.financialservices.v1.Instance",
"name": "projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID",
"createTime": CREATE_TIME,
"updateTime": UPDATE_TIME,
"state": "ACTIVE",
"kmsKey": "projects/KMS_PROJECT_ID/locations/LOCATION/keyRings/KEY_RING_ID/cryptoKeys/KEY_ID"
}
}
]
}
取消长时间运行的操作
使用 projects.locations.operations.cancel 方法对长时间运行的操作启动异步取消。服务器会尽全力取消操作,但不能保证一定成功。
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID:IAM 设置中列出的 Google Cloud 项目 IDLOCATION:操作的位置;请使用某个受支持的地区显示位置us-central1us-east1asia-south1europe-west1europe-west2europe-west4northamerica-northeast1southamerica-east1australia-southeast1
OPERATION_ID:操作的标识符
如需发送请求,请选择以下方式之一:
curl
执行以下命令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d "" \
"https://financialservices.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/operations/OPERATION_ID:cancel"
PowerShell
执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-Uri "https://financialservices.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/operations/OPERATION_ID:cancel" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
{}
删除长时间运行的操作
使用 projects.locations.operations.delete 方法可删除已完成的长时间运行的操作。此方法只是表明客户端不再关注操作结果,而不会取消操作。
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID:IAM 设置中列出的 Google Cloud 项目 IDLOCATION:操作的位置;请使用某个受支持的地区显示位置us-central1us-east1asia-south1europe-west1europe-west2europe-west4northamerica-northeast1southamerica-east1australia-southeast1
OPERATION_ID:操作的标识符
如需发送请求,请选择以下方式之一:
curl
执行以下命令:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://financialservices.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/operations/OPERATION_ID"
PowerShell
执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://financialservices.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/operations/OPERATION_ID" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
{}