0

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?.

rehan
  • 143
  • 3
  • 17

1 Answers1

0

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.

yyyyahir
  • 2,262
  • 1
  • 5
  • 14
  • so just to make it more clear. what i want is that the `pending` status should update once the job completes and should notify the user about the job completion. i have implemented the `job watcher` in my code but i am not sure if it's not doing what i want . i have added it in the question – rehan Sep 04 '19 at 07:54
  • Simply using the [`watch` method in the API](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#watch-job-v1-batch) (`GET /apis/batch/v1/watch/namespaces/{namespace}/jobs/{name}`) should stream the events comings from your job object. Then, you can use the Swagger callback to asynchronously listen to the events until you have your desired state. – yyyyahir Sep 09 '19 at 12:03