【问题标题】:Waiting with gcloud on "detect-text-pdf" operation在“detect-text-pdf”操作中等待 gcloud
【发布时间】:2022-06-16 03:31:59
【问题描述】:

我正在使用 gcloud 运行 detect-text-pdf

$ gcloud ml vision detect-text-pdf gs://my-bucket/pdfs/D.pdf gs://my-bucket/pdfs/D

导致如下输出:

{
  "name": "projects/PROJECT_ID/operations/OPERATION_ID"
}

其中PROJECT_ID 是项目,OPERATION_ID 是十六进制数字。

如何等待操作完成? 我试过了:

gcloud services operations wait OPERATION_ID

但我得到了错误:

ERROR: gcloud crashed (ArgumentTypeError): Invalid value 'OPERATION_ID': Operation format should be operations/namespace.id

如果这有帮助,我正在使用 colab 笔记本运行。

【问题讨论】:

  • 你试过gcloud services operations wait operations/OPERATION_ID吗?
  • @DazWilkin 谢谢!。是的,我试过了 - 结果相同(崩溃)
  • @lazy1 您能否编辑您的问题并分享您用来拥有minimal code that reproduces the problem的代码
  • @RogelioMonter 你是对的!完成。

标签: google-colaboratory gcloud


【解决方案1】:

TL;DR 如何等待操作完成?

你不能使用gcloud services operations wait命令,但是你可以得到文档Working with long-running operations中显示的操作状态


来自gcloud ml vision detect-text-pdf 参考:

API 参考

此命令使用vision/v1 API。此 API 的完整文档可在以下位置找到:https://cloud.google.com/vision/

另外,如文档Detect text in files (PDF/TIFF)所示:

一个成功的asyncBatchAnnotate 请求返回一个带有单个名称字段的响应:

{  
    "name":  "projects/usable-auth-library/operations/**1efec2285bd442df**"  
}  

此名称表示具有关联 ID(例如,1efec2285bd442df)的长时间运行的操作,可以使用 v1.operations API 进行查询。

要检索您的 Vision 注释响应,请向 v1.operations 端点发送 GET 请求,并在 URL 中传递操作 ID:

GET https://vision.googleapis.com/v1/operations/operation-id

如参考和文档中所示,这些是使用v1.operations API 的长时间运行的操作。因此,您不能使用gcloud services operations wait 命令,但您可以获得文档Working with long-running operations 中显示的操作状态:

您请求的一些操作是长时间运行的,...这些类型的请求将返回带有操作 ID 的 JSON,您可以使用该 ID 来获取操作状态。

Get an operation code samples 部分,有一些说明可以请求您长期运行的操作状态。

HTTP 方法和 URL:

GET https://automl.googleapis.com/v1/projects/project-id/locations/us-central1/operations/operation-id

要使用curl 发送您的请求,请执行以下命令:

curl -X GET \  
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \  
"https://automl.googleapis.com/v1/projects/project-id/locations/us-central1/operations/operation-id"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-09
    • 2015-02-02
    • 2016-03-07
    • 2021-12-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-03
    相关资源
    最近更新 更多