管理长时间运行的操作

本页介绍了如何管理 Live Stream API 长时间运行的操作 (LRO) 的生命周期。

如果方法调用可能需要很长时间才能完成,系统就会返回长时间运行的操作。例如,Live Stream API 会在您每次调用 projects.locations.inputs.create 时创建一个 LRO。LRO 会跟踪处理作业的状态。

您可以使用 Live Stream API 提供的 projects.locations.operations 方法来检查 LRO 的状态。您还可以对 LRO 执行 list、cancel 或 delete 操作。

LRO 会在 Google Cloud 项目和位置层级上加以管理。向该 API 发出请求时,请在其中提供 Google Cloud 项目以及 LRO 的运行位置。

在 LR 完成之后,LRO 的记录会保留大约 30 天,也就是说,在这段时间之后,您将无法再查看或列出 LRO。

获取长时间运行的操作的详细信息

假设您创建了输入端点。响应中的 name 值表明,Live Stream API 创建了一个名为 projects/PROJECT_NUMBER/locations/LOCATION/operations/OPERATION_ID 的 LRO。

如需检查是否已创建输入端点,请使用 projects.locations.operations.get 方法。如果响应包含 "done": false,请重复该命令,直到响应包含 "done": true。此操作可能需要几分钟才能完成。

您还可以通过列出长时间运行的操作来检索 LRO 名称。

在使用任何请求数据之前,请先进行以下替换:

  • PROJECT_NUMBER:您的 Google Cloud 项目编号;此值位于 IAM 设置页面上的“项目编号”字段中
  • LOCATION:输入端点所在的位置;请使用某个受支持的地区
    显示位置
    • us-central1
    • us-east1
    • us-east4
    • us-west1
    • us-west2
    • northamerica-northeast1
    • southamerica-east1
    • asia-east1
    • asia-east2
    • asia-south1
    • asia-northeast1
    • asia-southeast1
    • australia-southeast1
    • europe-north1
    • europe-west1
    • europe-west2
    • europe-west3
    • europe-west4
  • OPERATION_ID:操作的标识符

如需发送您的请求,请展开以下选项之一:

您应该收到类似以下内容的 JSON 响应:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.video.livestream.v1.OperationMetadata",
    "createTime": CREATE_TIME,
    "endTime": END_TIME,
    "target": "projects/PROJECT_NUMBER/locations/LOCATION/inputs/INPUT_ID",
    "verb": "create",
    "requestedCancellation": false,
    "apiVersion": "v1"
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.cloud.video.livestream.v1.Input",
    "name": "projects/PROJECT_NUMBER/locations/LOCATION/inputs/INPUT_ID",
    "createTime": CREATE_TIME,
    "updateTime": UPDATE_TIME,
    "type": "RTMP_PUSH",
    "uri":  INPUT_STREAM_URI, # For example, "rtmp://1.2.3.4/live/b8ebdd94-c8d9-4d88-a16e-b963c43a953b",
    "tier": "HD"
  }
}

列出长时间运行的操作

如需列出指定位置中的所有操作,请使用 projects.locations.operations.list 方法。

在使用任何请求数据之前,请先进行以下替换:

  • PROJECT_NUMBER:您的 Google Cloud 项目编号;此值位于 IAM 设置页面上的“项目编号”字段中
  • LOCATION:操作的位置;请使用某个受支持的地区
    显示位置
    • us-central1
    • us-east1
    • us-east4
    • us-west1
    • us-west2
    • northamerica-northeast1
    • southamerica-east1
    • asia-east1
    • asia-east2
    • asia-south1
    • asia-northeast1
    • asia-southeast1
    • australia-southeast1
    • europe-north1
    • europe-west1
    • europe-west2
    • europe-west3
    • europe-west4

如需发送您的请求,请展开以下选项之一:

您应该收到类似以下内容的 JSON 响应:

{
  "operations": [
    {
      "name": "projects/PROJECT_NUMBER/locations/LOCATION/operations/OPERATION_ID",
      "metadata": {
        "@type": "type.googleapis.com/google.cloud.livestream.v1.OperationMetadata",
        "createTime": CREATE_TIME,
        "endTime": END_TIME,
        "target": "projects/PROJECT_NUMBER/locations/LOCATION/inputs/INPUT_ID,
        "verb": "create",
        "requestedCancellation": false,
        "apiVersion": "v1"
      },
      "done": false
    },
    {
      "name": "projects/PROJECT_NUMBER/locations/LOCATION/operations/my-other-operation",
      "metadata": {
        "@type": "type.googleapis.com/google.cloud.livestream.v1.OperationMetadata",
        "createTime": CREATE_TIME,
        "endTime": END_TIME,
        "target": "projects/PROJECT_NUMBER/locations/LOCATION/inputs/my-other-input",
        "verb": "create",
        "requestedCancellation": false,
        "apiVersion": "v1"
      },
      "done": true,
      "response": {
        "@type": "type.googleapis.com/google.cloud.livestream.v1.Input",
        "name": "projects/PROJECT_NUMBER/locations/LOCATION/inputs/my-other-input",
        "createTime": CREATE_TIME,
        "updateTime": UPDATE_TIME,
        "type": "RTMP_PUSH",
        "uri":  INPUT_STREAM_URI,
        "tier": "HD"
      }
    }
  ]
}

取消长时间运行的操作

如需对长时间运行的操作启动异步取消,请使用 projects.locations.operations.cancel 方法。服务器会尽全力取消操作,但不能保证一定成功。

在使用任何请求数据之前,请先进行以下替换:

  • PROJECT_NUMBER:您的 Google Cloud 项目编号;此值位于 IAM 设置页面上的“项目编号”字段中
  • LOCATION:操作的位置;请使用某个受支持的地区
    显示位置
    • us-central1
    • us-east1
    • us-east4
    • us-west1
    • us-west2
    • northamerica-northeast1
    • southamerica-east1
    • asia-east1
    • asia-east2
    • asia-south1
    • asia-northeast1
    • asia-southeast1
    • australia-southeast1
    • europe-north1
    • europe-west1
    • europe-west2
    • europe-west3
    • europe-west4
  • OPERATION_ID:操作的标识符

如需发送您的请求,请展开以下选项之一:

您应该会收到一个空的 JSON 对象作为响应:
{}

删除长时间运行的操作

如需删除已完成的长时间运行操作,请使用 projects.locations.operations.delete 方法。此方法只是表明客户端不再关注操作结果,而不会取消操作。

在使用任何请求数据之前,请先进行以下替换:

  • PROJECT_NUMBER:您的 Google Cloud 项目编号;此值位于 IAM 设置页面上的“项目编号”字段中
  • LOCATION:操作的位置;请使用某个受支持的地区
    显示位置
    • us-central1
    • us-east1
    • us-east4
    • us-west1
    • us-west2
    • northamerica-northeast1
    • southamerica-east1
    • asia-east1
    • asia-east2
    • asia-south1
    • asia-northeast1
    • asia-southeast1
    • australia-southeast1
    • europe-north1
    • europe-west1
    • europe-west2
    • europe-west3
    • europe-west4
  • OPERATION_ID:操作的标识符

如需发送您的请求,请展开以下选项之一:

您应该会收到一个空的 JSON 对象作为响应:
{}