From 831b7e8abec524bec00329db35d33c0c9005ff29 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Sat, 23 Nov 2019 03:48:43 +0530 Subject: [PATCH] autogenview: implement recursive action polling This implements polling in the detail view and refreshes detail view on async job/action completion (in both success and failure cases. Signed-off-by: Rohit Yadav --- ui/src/components/header/HeaderNotice.vue | 2 +- ui/src/views/AutogenView.vue | 29 ++++++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/ui/src/components/header/HeaderNotice.vue b/ui/src/components/header/HeaderNotice.vue index 6170d89f485..c796a6251fd 100644 --- a/ui/src/components/header/HeaderNotice.vue +++ b/ui/src/components/header/HeaderNotice.vue @@ -79,7 +79,7 @@ export default { startPolling () { this.poller = setInterval(() => { this.pollJobs() - }, 2500) + }, 4000) }, async pollJobs () { var hasUpdated = false diff --git a/ui/src/views/AutogenView.vue b/ui/src/views/AutogenView.vue index 76f822652ec..c28356289d0 100644 --- a/ui/src/views/AutogenView.vue +++ b/ui/src/views/AutogenView.vue @@ -508,6 +508,22 @@ export default { }).then(function () { }) }, + pollActionCompletion (jobId, action) { + api('queryAsyncJobResult', { jobid: jobId }).then(json => { + var result = json.queryasyncjobresultresponse + if (result.jobstatus === 1) { + this.fetchData() + } else if (result.jobstatus === 2) { + this.fetchData() + } else { + this.$message + .loading(this.$t(action.label) + ' in progress for ' + this.resource.name, 3) + .then(() => this.pollActionCompletion(jobId, action)) + } + }).catch(function (e) { + console.log('Error encountered while fetching async job result' + e) + }) + }, handleSubmit (e) { e.preventDefault() this.form.validateFields((err, values) => { @@ -544,12 +560,15 @@ export default { params.id = this.resource.id } + var hasJobId = false api(this.currentAction.api, params).then(json => { for (const obj in json) { if (obj.includes('response')) { for (const res in json[obj]) { if (res === 'jobid') { this.$store.dispatch('AddAsyncJob', { title: this.$t(this.currentAction.label), jobid: json[obj][res], description: this.resource.name, status: 'progress' }) + this.pollActionCompletion(json[obj][res], this.currentAction) + hasJobId = true break } } @@ -558,6 +577,10 @@ export default { } if (this.currentAction.icon === 'delete') { this.$router.go(-1) + } else { + if (!hasJobId) { + this.fetchData() + } } }).catch(error => { console.log(error) @@ -568,12 +591,6 @@ export default { }).finally(f => { this.closeAction() }) - - // TODO: listen for notification success/fail and refresh - const fetchData = this.fetchData - setTimeout(function () { - fetchData() - }, 2500) } }) },