i have deployed my front end application through a deployment.yaml
file using minikube having swagger-ui
. This application simply takes in json queries and starts jobs on minikube which runs and terminates relevant containers. currently i have built 1 docker image on my minikube cluster which starts downloading satellite images after the job is started. Now whenever i pass a json query to swagger-ui, it gives me the following response where the job status is 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. However, when i try to run a GET
query to list all jobs, there i see the completed job. 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. Furthermore, it looks like you're using GET
to query the status of the job afterwards, which will also result in the expected behavior.
Now, Swagger has support for long polling via callbacks and the Kubernetes API has read support for the verb 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.
This feature also extends to your specific object Job
.
Enabling callbacks and listening to the API via watch
will get you the same result as running:
$ 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.