Skip to content

Commit

Permalink
log stream api port into jobs vue
Browse files Browse the repository at this point in the history
  • Loading branch information
rhanka committed Apr 30, 2018
1 parent 296ae8a commit 2dff7d3
Showing 1 changed file with 36 additions and 20 deletions.
56 changes: 36 additions & 20 deletions src/components/Jobs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export default {
},
data () {
return {
evtSource: null,
runningJobs: {},
doneJobs: {},
log: null,
Expand All @@ -150,19 +151,10 @@ export default {
this.getLog(this.$route.params.job)
}
},
mounted () {
created () {
this.getJobs()
window.bus.$on('updateJobs', v => {
this.runningJobs = v.running
this.doneJobs = v.done
})
if (this.$route.name === 'job') {
this.interval.jobs = setInterval(() => {
this.getLog(this.$route.params.job)
}, 5000)
}
},
mounted () {
},
computed: {
filteredLog () {
Expand Down Expand Up @@ -195,17 +187,41 @@ export default {
.then(response => {
this.runningJobs = response.body.running
this.doneJobs = response.body.done
if (this.$route.name === 'job') {
this.getLog(this.$route.params.job)
}
})
},
getLog (recipe) {
this.$http.get(this.apiUrl + 'recipes/' + recipe + '/log')
.then(response => {
let arr = response.body.split('\n')
if ((this.log === null) || (arr.length !== this.log.length)) {
this.log = arr
this.setPageCurrent(Math.ceil(this.log.length / this.pageSize))
}
})
if (this.runningJobs.some(r => { return r.recipe === recipe })) {
this.getRunningLog(recipe)
} else {
this.$http.get(this.apiUrl + 'recipes/' + recipe + '/log')
.then(response => {
let arr = response.body.split('\n')
if ((this.log === null) || (arr.length !== this.log.length)) {
this.log = arr
this.setPageCurrent(Math.ceil(this.log.length / this.pageSize))
}
})
if (this.evtSource !== null) {
this.evtSource.close()
}
}
},
getRunningLog (recipe) {
this.evtSource = new EventSource(this.apiUrl + 'recipes/' + recipe + '/log')
let that = this
this.evtSource.addEventListener('open', function (e) {
that.log = []
}, false)
this.evtSource.addEventListener('message', function (e) {
that.log = that.log.concat(e.data.split('\n'))
that.setPageCurrent(Math.ceil(that.log.length / that.pageSize))
}, false)
this.evtSource.addEventListener('close', function (e) {
that.evtSource.close()
}, false)
}
}
}
Expand Down

0 comments on commit 2dff7d3

Please sign in to comment.