Skip to content

Commit 5e1584e

Browse files
authored
Add polling to get realtime job output (#52)
Add polling to get realtime job output
1 parent 1ffd16c commit 5e1584e

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes to `cybercog/laravel-paket` will be documented in this file.
88

99
- ([#48]) Added repositories tab
1010
- ([#51]) Added refetch data button in top menu
11+
- ([#52]) Added polling to get realtime job output
1112

1213
## [1.4.0]
1314

@@ -58,6 +59,7 @@ All notable changes to `cybercog/laravel-paket` will be documented in this file.
5859
[1.2.0]: https://github.com/cybercog/laravel-paket/compare/1.1.0...1.2.0
5960
[1.1.0]: https://github.com/cybercog/laravel-paket/compare/1.0.0...1.1.0
6061

62+
[#52]: https://github.com/cybercog/laravel-paket/pull/52
6163
[#51]: https://github.com/cybercog/laravel-paket/pull/51
6264
[#48]: https://github.com/cybercog/laravel-paket/pull/48
6365
[#47]: https://github.com/cybercog/laravel-paket/pull/47

resources/js/screens/jobs/item.vue

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
},
4646
4747
mounted() {
48-
this.fetchData();
48+
this.autoRefreshData();
4949
},
5050
5151
computed: {
@@ -59,12 +59,24 @@
5959
},
6060
6161
methods: {
62+
autoRefreshData() {
63+
setTimeout(async () => {
64+
await this.fetchData();
65+
66+
if (this.job.status === 'Pending' || this.job.status === 'Running') {
67+
this.autoRefreshData();
68+
}
69+
}, 1000);
70+
},
71+
6272
async fetchData() {
6373
const response = await this.$store.getters.getJob(this.$route.params.id);
6474
65-
this.job = response.data;
75+
if (typeof response !== 'undefined') {
76+
this.job = response.data;
6677
67-
this.job.process.output = this.asHtml(this.job.process.output);
78+
this.job.process.output = this.asHtml(this.job.process.output);
79+
}
6880
},
6981
7082
asHtml(string) {

resources/js/store.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,14 @@ const getters = {
129129
return state.jobs;
130130
},
131131

132-
getJob: (state, getters) => (jobId) => {
133-
return Axios.get(getters.getUrl(`/api/jobs/${jobId}`));
132+
getJob: (state, getters) => async (jobId) => {
133+
const url = getters.getUrl(`/api/jobs/${jobId}`);
134+
135+
try {
136+
return await Axios.get(url);
137+
} catch (exception) {
138+
console.warn(`Cannot fetch ${url}`);
139+
}
134140
},
135141

136142
getRequirementJobs: (state, getters) => (requirement) => {

0 commit comments

Comments
 (0)