Skip to content

Commit 831b7e8

Browse files
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 <rohit.yadav@shapeblue.com>
1 parent 0f968f5 commit 831b7e8

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

ui/src/components/header/HeaderNotice.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export default {
7979
startPolling () {
8080
this.poller = setInterval(() => {
8181
this.pollJobs()
82-
}, 2500)
82+
}, 4000)
8383
},
8484
async pollJobs () {
8585
var hasUpdated = false

ui/src/views/AutogenView.vue

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,22 @@ export default {
508508
}).then(function () {
509509
})
510510
},
511+
pollActionCompletion (jobId, action) {
512+
api('queryAsyncJobResult', { jobid: jobId }).then(json => {
513+
var result = json.queryasyncjobresultresponse
514+
if (result.jobstatus === 1) {
515+
this.fetchData()
516+
} else if (result.jobstatus === 2) {
517+
this.fetchData()
518+
} else {
519+
this.$message
520+
.loading(this.$t(action.label) + ' in progress for ' + this.resource.name, 3)
521+
.then(() => this.pollActionCompletion(jobId, action))
522+
}
523+
}).catch(function (e) {
524+
console.log('Error encountered while fetching async job result' + e)
525+
})
526+
},
511527
handleSubmit (e) {
512528
e.preventDefault()
513529
this.form.validateFields((err, values) => {
@@ -544,12 +560,15 @@ export default {
544560
params.id = this.resource.id
545561
}
546562
563+
var hasJobId = false
547564
api(this.currentAction.api, params).then(json => {
548565
for (const obj in json) {
549566
if (obj.includes('response')) {
550567
for (const res in json[obj]) {
551568
if (res === 'jobid') {
552569
this.$store.dispatch('AddAsyncJob', { title: this.$t(this.currentAction.label), jobid: json[obj][res], description: this.resource.name, status: 'progress' })
570+
this.pollActionCompletion(json[obj][res], this.currentAction)
571+
hasJobId = true
553572
break
554573
}
555574
}
@@ -558,6 +577,10 @@ export default {
558577
}
559578
if (this.currentAction.icon === 'delete') {
560579
this.$router.go(-1)
580+
} else {
581+
if (!hasJobId) {
582+
this.fetchData()
583+
}
561584
}
562585
}).catch(error => {
563586
console.log(error)
@@ -568,12 +591,6 @@ export default {
568591
}).finally(f => {
569592
this.closeAction()
570593
})
571-
572-
// TODO: listen for notification success/fail and refresh
573-
const fetchData = this.fetchData
574-
setTimeout(function () {
575-
fetchData()
576-
}, 2500)
577594
}
578595
})
579596
},

0 commit comments

Comments
 (0)