[英]How to update kubernetes job status of a job after being executed through swagger running a container deployment?
i have deployed my front end application through a deployment.yaml
file using minikube having swagger-ui
. 我走过了我的部署前端应用
deployment.yaml
文件使用minikube有swagger-ui
。 This application simply takes in json queries and starts jobs on minikube which runs and terminates relevant containers. 该应用程序仅接受json查询并在minikube上启动作业,该作业可运行并终止相关容器。 currently i have built 1 docker image on my minikube cluster which starts downloading satellite images after the job is started.
目前,我在minikube集群上构建了1个docker映像,该映像在作业开始后开始下载卫星映像。 Now whenever i pass a json query to swagger-ui, it gives me the following response where the job status is
PENDING
: 现在,每当我向swagger-ui传递一个json查询时,它都会给我以下响应,其中作业状态为
PENDING
:
{
"workflowId": "2a94d0e3-7245-47e4-a9ce-821efce42eb8",
"workflowName": "monitoring1",
"status": "PENDING",
"submittedAt": "2019-08-29T08:22:59.599469Z",
"completedAt": null,
"jobs": [
Job watcher 求职者
var jobStatus = JobStatus.PENDING
when (action) {
Watcher.Action.ADDED -> {
if (job.status.startTime != null && job.status.active >= 0) {
jobStatus = JobStatus.RUNNING
}
}
Watcher.Action.MODIFIED -> {
if (job.status.completionTime != null && job.status.succeeded >= 0) {
jobStatus = JobStatus.COMPLETED
} else if (job.status.failed != null) {
jobStatus = JobStatus.ERROR
}
}
Watcher.Action.DELETED -> {
log.info("DELETED")
}
Watcher.Action.ERROR -> {
jobStatus = JobStatus.ERROR
}
}
on the minikuber side, the job starts and terminates after some time but on the side of swagger, the status of job never changes. 在minikuber一侧,作业会在一段时间后开始和终止,但是在摇摇欲坠的一侧,作业的状态永远不会改变。 However, when i try to run a
GET
query to list all jobs, there i see the completed job. 但是,当我尝试运行
GET
查询以列出所有作业时,我看到了完成的作业。 My question is how can i update status or notify the user once the job completes? 我的问题是工作完成后如何更新状态或通知用户? .
。
It might be how the question is worded, but after starting a job, is expected to get a PENDING
status as the immediate response, as the job hasn't finished yet. 问题的措辞可能是这样,但是开始工作后,由于工作尚未完成,因此有望立即获得“
PENDING
状态作为立即响应。 Furthermore, it looks like you're using GET
to query the status of the job afterwards, which will also result in the expected behavior. 此外,看起来您之后正在使用
GET
查询作业的状态,这也将导致预期的行为。
Now, Swagger has support for long polling via callbacks and the Kubernetes API has read support for the verb WATCH
: 现在,Swagger支持通过回调进行长时间轮询 ,而Kubernetes API已读取对动词
WATCH
支持 :
Watch will stream results for an object(s) as it is updated.
监视将在更新对象时流式传输对象的结果。 Similar to a callback, watch is used to respond to resource changes.
类似于回调,watch用于响应资源更改。
This feature also extends to your specific object Job
. 此功能还扩展到您的特定对象
Job
。
Enabling callbacks and listening to the API via watch
will get you the same result as running: 启用回调并通过
watch
监听API,将获得与运行相同的结果:
$ kubectl get job example-job --watch -o json
So any changes to the object will be reflected as they happen, returning a JSON result that you can use later to feed your client. 因此,对对象的任何更改都会在发生时反映出来,并返回一个JSON结果,您以后可以使用它来提供给客户端。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.