为什么`gcloud run jobsexecute`会惩罚你的等待?

问题描述 投票:0回答:1

如果我跑步:

gcloud run jobs execute foo --project myproj --region us-central1 --format json

它为在云中生成的执行资源返回一个大而漂亮的数据结构。 无论执行最终是否失败,都会发生这种情况。

但是,如果我跑步:

gcloud run jobs execute foo --project myproj --region us-central1 --format json --wait

如果作业失败,我什么也得不到——只是将几行纯文本错误报告写入 STDERR。 没有任何结构可以让我编写工具。

X Creating execution... Task foo-8vn7q-task0 failed with message: The container exited with an error.                                                          
  ✓ Provisioning resources...                                                                                                                                    
  ✓ Starting execution...                                                                                                                                        
  X Running execution... 0 / 1 complete                                                                                                                          
Executing job failed                                                                                                                                             
ERROR: (gcloud.run.jobs.execute) The execution failed.
View details about this execution by running:
gcloud run jobs executions describe foo-8vn7q

Or visit https://console.cloud.google.com/run/jobs/executions/details/us-central1/foo-8vn7q/tasks?project=xxx

为什么? 等待更长时间应该会产生“更多”数据,而不是更少。 为什么 gcloud 会因为我等待而惩罚我? 为什么不仍然返回执行记录,而是记录失败状态? (事后 gcloud run jobs executions describe 产生相同的输出。)


此外...我愿意让我的工具对此进行补偿,如果 gcloud 在执行时返回非零退出代码,则使用
describe

命令进行跟踪 - 如果该命令有

我可以使用 --wait
标志来阻止作业执行完成。 但事实并非如此。 这样就只剩下投票了。
与此同时,我将让我的工具禁止执行 

--wait

标志,以便完全避免这种情况。

    

google-cloud-platform gcloud google-cloud-run google-cloud-run-jobs
1个回答
0
投票
--log-http

添加到

gcloud
命令,您将看到底层方法调用并更深入地了解命令的实现方式。
有趣的是,

gcloud run jobs

使用v1 API而不是v2。

当您

gcloud run jobs execute

时,命令:


    POST
  1. namespaces.jobs.run
    
    
    使用返回的
  2. Execution
     来获取 
    ObjectMeta
     
    selfLink
    使用自链接(反复)
  3. namespaces.executions.get
    更新了
    Execution
  4. 该实现有效地轮询端点,询问对返回的
Executions

ExecutionsStatus
 的更新。
不等待和等待(

--wait

)的区别在于:


不等待执行开始运行;和
  • 等待直到执行完成(或失败)。
  • 因此,在您等待 Google 修改
gcloud run jobs execute

的行为之前,您可以直接执行(例如

curl
)方法来实现您想要的行为,包括始终返回
Execution
备注:

有一组
    gcloud beta run jobs
  1. 命令,但这些命令也使用 v1 API,并且行为似乎没有不同。
    有一个 v2 API(
  2. gcloud
  3. 未使用),它会向
    Operation
     方法返回 
    projects.locations.jobs.run
    ,该方法与其他长时间运行的请求更好地保持一致。
© www.soinside.com 2019 - 2024. All rights reserved.