我正在使用 python 和 google.cloud.tasks_v2。在应用程序引擎中部署我的服务后,我创建任务,它创建并成功执行,但是如果方法 client.get_task() 不返回任何相关信息,我如何获取任务状态或任务执行结果?
最佳答案
要获取有关您正在运行的指定云任务的信息,您可以使用 command line并使用像 subprocess
这样的包将其集成到您的 Python 代码中来运行以下命令:
gcloud 任务描述 TASK [--queue=QUEUE]
此外,如果您想查看任务尝试的状态,您可以使用以下命令 Cloud Task API.
它将通过以下 JSON 表示形式为您提供有关任务尝试状态的信息:
{
"scheduleTime": string,
"dispatchTime": string,
"responseTime": string,
"responseStatus": {
object (Status)
}
}
要查看任务第一次尝试 firstAttempt
的状态或任务最后一次尝试 lastAttempt
的状态,您可以使用 following method在云任务 API 中。
如上所述here,请记住,如果您在 Cloud Tasks 队列中使用 App Engine 任务,则代码状态将如下所示:
The task attempt has succeeded if the app's request handler returns an HTTP response code in the range [200 - 299]. The task attempt has failed if the app's handler returns a non-2xx response code or Cloud Tasks does not receive response before the deadline.
关于python - 有没有办法获取谷歌云任务状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59469004/