如何知道批量云预测何时结束
How to know when batch cloud prediction ends
我正在做一个接收一些数据的应用程序,处理它然后创建一个预测人工智能批处理作业。预测完成后,我应该把它们全部拿走并将它们与以前的文件合并。批量预测写入一个桶,我们称之为 gs://predictions
.
目前,我有一个云函数,每当写入 gs://predictions
时就会触发该函数。然而,批量预测作业将数据流式传输到文件中,当有大量预测要进行时,会多次更新此类文件。这意味着当我只想在作业完成时调用它时,我的云函数被触发了很多次。
为了克服这个问题,现在调用云函数,然后检查作业是否完成。如果是,则处理该文件;如果没有,让它滑动。这当然会带来很多不必要的处理(和不必要的代码!):-(
什么对我真正有帮助:批处理作业完成后能否以某种方式写入 Pub/Sub?或者更好的是,它可以使用 webhook 以便在完成时自己调用我的云函数吗?
我试图查看文档,但找不到任何东西。
是否有任何其他建议的解决方案?
您可以create a log sink into PubSub并在此自定义过滤器上过滤日志:
resource.type="ml_job"
textPayload="Job completed successfully."
然后,当批处理作业完成时,将打印日志跟踪并将消息发布到 PubSub 主题中。
参考文档Google Cloud Training job docs
为了获得 AI Platform 作业状态,您可以使用 GCP 提供的 REST API,参考作业 AI Platform jobs docs
GET 请求正文:
{
"jobId": string,
"createTime": string,
"startTime": string,
"endTime": string,
"state": enum (State), # This Field is what will tell you status of job
"errorMessage": string,
"labels": {
string: string,
...
},
"etag": string,
// Union field input can be only one of the following:
"trainingInput": {
object (TrainingInput)
},
"predictionInput": {
object (PredictionInput)
}
// End of list of possible types for union field input.
// Union field output can be only one of the following:
"trainingOutput": {
object (TrainingOutput)
},
"predictionOutput": {
object (PredictionOutput)
}
// End of list of possible types for union field output.
}
状态字段是枚举
Enums
STATE_UNSPECIFIED The job state is unspecified.
QUEUED The job has been just created and processing has not yet begun.
PREPARING The service is preparing to run the job.
RUNNING The job is in progress.
SUCCEEDED The job completed successfully.
FAILED The job failed. errorMessage should contain the details of the failure.
CANCELLING The job is being cancelled. errorMessage should describe the reason for the cancellation.
CANCELLED The job has been cancelled. errorMessage should describe the reason for the cancellation.
注意:所有这些都可以通过 python 或任何其他选择的语言来完成。
Using Python GCP Client Libraries
我正在做一个接收一些数据的应用程序,处理它然后创建一个预测人工智能批处理作业。预测完成后,我应该把它们全部拿走并将它们与以前的文件合并。批量预测写入一个桶,我们称之为 gs://predictions
.
目前,我有一个云函数,每当写入 gs://predictions
时就会触发该函数。然而,批量预测作业将数据流式传输到文件中,当有大量预测要进行时,会多次更新此类文件。这意味着当我只想在作业完成时调用它时,我的云函数被触发了很多次。
为了克服这个问题,现在调用云函数,然后检查作业是否完成。如果是,则处理该文件;如果没有,让它滑动。这当然会带来很多不必要的处理(和不必要的代码!):-(
什么对我真正有帮助:批处理作业完成后能否以某种方式写入 Pub/Sub?或者更好的是,它可以使用 webhook 以便在完成时自己调用我的云函数吗? 我试图查看文档,但找不到任何东西。
是否有任何其他建议的解决方案?
您可以create a log sink into PubSub并在此自定义过滤器上过滤日志:
resource.type="ml_job"
textPayload="Job completed successfully."
然后,当批处理作业完成时,将打印日志跟踪并将消息发布到 PubSub 主题中。
参考文档Google Cloud Training job docs 为了获得 AI Platform 作业状态,您可以使用 GCP 提供的 REST API,参考作业 AI Platform jobs docs
GET 请求正文:
{
"jobId": string,
"createTime": string,
"startTime": string,
"endTime": string,
"state": enum (State), # This Field is what will tell you status of job
"errorMessage": string,
"labels": {
string: string,
...
},
"etag": string,
// Union field input can be only one of the following:
"trainingInput": {
object (TrainingInput)
},
"predictionInput": {
object (PredictionInput)
}
// End of list of possible types for union field input.
// Union field output can be only one of the following:
"trainingOutput": {
object (TrainingOutput)
},
"predictionOutput": {
object (PredictionOutput)
}
// End of list of possible types for union field output.
}
状态字段是枚举
Enums
STATE_UNSPECIFIED The job state is unspecified.
QUEUED The job has been just created and processing has not yet begun.
PREPARING The service is preparing to run the job.
RUNNING The job is in progress.
SUCCEEDED The job completed successfully.
FAILED The job failed. errorMessage should contain the details of the failure.
CANCELLING The job is being cancelled. errorMessage should describe the reason for the cancellation.
CANCELLED The job has been cancelled. errorMessage should describe the reason for the cancellation.
注意:所有这些都可以通过 python 或任何其他选择的语言来完成。 Using Python GCP Client Libraries