This is an automated email from the ASF dual-hosted git repository.
rohit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack-primate.git
The following commit(s) were added to refs/heads/master by this push:
new 401e797 autogenview: implement recursive action polling
401e797 is described below
commit 401e79703c5bda4fd8d783d89aa7fc259a5066f5
Author: Rohit Yadav <[email protected]>
AuthorDate: Sat Nov 23 03:48:43 2019 +0530
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 <[email protected]>
---
src/components/header/HeaderNotice.vue | 2 +-
src/views/AutogenView.vue | 29 +++++++++++++++++++++++------
2 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/src/components/header/HeaderNotice.vue
b/src/components/header/HeaderNotice.vue
index 6170d89..c796a62 100644
--- a/src/components/header/HeaderNotice.vue
+++ b/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/src/views/AutogenView.vue b/src/views/AutogenView.vue
index 76f8226..c283562 100644
--- a/src/views/AutogenView.vue
+++ b/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)
}
})
},