本页面介绍如何管理 Financial Services API 的生命周期 长时间运行的操作 (LRO)。
系统将返回长时间运行的操作,
可能需要很长时间才能完成。例如,Financial Services API
每次调用都会创建一个 LRO
projects.locations.instances.create
。
LRO 会跟踪处理作业的状态。
您可以使用 projects.locations.operations
方法
Financial Services API 提供的用于检查 的状态
LRO。你还可以列出、取消
或删除 LRO。
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
:列出的 Google Cloud 项目 ID 在 IAM 设置中LOCATION
:实例的位置;使用以下任一 该 支持的区域显示位置us-central1
us-east1
asia-south1
europe-west1
europe-west2
europe-west4
northamerica-northeast1
southamerica-east1
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-central1
us-east1
asia-south1
europe-west1
europe-west2
europe-west4
northamerica-northeast1
southamerica-east1
如需发送请求,请选择以下方式之一:
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-central1
us-east1
asia-south1
europe-west1
europe-west2
europe-west4
northamerica-northeast1
southamerica-east1
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-central1
us-east1
asia-south1
europe-west1
europe-west2
europe-west4
northamerica-northeast1
southamerica-east1
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 响应:
{}