Skip to content

Commit 532fe83

Browse files
authored
Update job result polling (#120)
* poll status endpoint when waiting for result completion, add simple error state handling * add error status handling * lint
1 parent 407798c commit 532fe83

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

dashboard/src/api/jobs.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,6 @@ export async function getSingleResult(
6464
export async function compute(token: string, jobId: string) {
6565
return jobsRequest(token, "post", null, null, `${jobId}/compute`);
6666
}
67+
export async function jobStatus(token: string, jobId: string) {
68+
return jobsRequest(token, "get", null, null, `${jobId}/status`);
69+
}

dashboard/src/components/jobs/JobHandler.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ export default class JobHandler extends Vue {
425425
if (this.job) {
426426
if (this.jobStatus == "incomplete") {
427427
return "Data Upload Required";
428+
} else if (this.jobStatus == "error") {
429+
return "An error occurred";
428430
} else if (this.jobStatus == "prepared") {
429431
return "Ready For Calculation";
430432
} else {
@@ -442,6 +444,8 @@ export default class JobHandler extends Vue {
442444
return "Ready";
443445
} else if (this.jobStatus == "queued") {
444446
return "Queued";
447+
} else if (this.jobStatus == "error") {
448+
return "An error occurred";
445449
} else {
446450
return "Calculation Not Submitted";
447451
}

dashboard/src/components/jobs/JobResults.vue

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ Component for handling display/download of job results.
4747
<template v-else-if="jobStatus == 'running'">
4848
The calculation is running and will be ready soon.
4949
</template>
50+
<template v-else-if="jobStatus == 'error'">
51+
An error occured while processing the calculation.
52+
</template>
53+
<template v-else-if="jobStatus == 'complete'">
54+
Calculation is complete. Results are loading.
55+
</template>
5056
<template v-else>
5157
Calculation has not been submitted.
5258
</template>
@@ -88,20 +94,37 @@ export default class JobResults extends Vue {
8894
this.initializeResults();
8995
}
9096
} else {
91-
this.awaitCompletion();
97+
this.pollUntilComplete();
9298
}
9399
}
94100
deactivated() {
95101
clearTimeout(this.timeout);
96102
}
97-
awaitCompletion() {
98-
// emit an event to fetch the job and check the new status
99-
this.$emit("reload-job");
100-
if (this.jobStatus == "complete") {
103+
async pollUntilComplete() {
104+
const token = await this.$auth.getTokenSilently();
105+
this.awaitCompletion(token);
106+
}
107+
async awaitCompletion(token: string) {
108+
// fetch the job status until we find something meaningful to report.
109+
const statusRequest = await Jobs.jobStatus(
110+
token,
111+
this.job.object_id
112+
).then(response => response.json());
113+
const jobStatus = statusRequest.status;
114+
if (jobStatus != this.jobStatus) {
115+
// Emit an event to reload the job when the status has changed so that
116+
// JobHandler can react accordingly.
117+
this.$emit("reload-job");
118+
}
119+
if (jobStatus == "complete") {
120+
// load results when complete
101121
this.initializeResults();
122+
} else if (jobStatus == "error") {
123+
// discontinue polling
124+
return;
102125
} else {
103-
// If the job was not complete, check for
104-
this.timeout = setTimeout(this.awaitCompletion, 1000);
126+
// Wait 1 second and poll for status update
127+
this.timeout = setTimeout(this.awaitCompletion.bind(this, token), 1000);
105128
}
106129
}
107130
initializeResults() {
@@ -116,7 +139,8 @@ export default class JobResults extends Vue {
116139
selected: "",
117140
timeseriesData: null,
118141
summaryData: {},
119-
loadedSummaryData: []
142+
loadedSummaryData: [],
143+
errors: null
120144
};
121145
}
122146
get labelledSummaryResults() {

0 commit comments

Comments
 (0)