case 4192

This commit is contained in:
2022-09-28 19:13:20 +00:00
parent 4bb6a243ef
commit 293b3012aa

View File

@@ -19,6 +19,15 @@
@click="doAction()" @click="doAction()"
>{{ $ay.t("StartJob") }}</v-btn >{{ $ay.t("StartJob") }}</v-btn
> >
<v-btn
v-if="jobActive"
color="red darken-1"
text
@click="requestCancel()"
>
{{ $ay.t("Cancel") }}</v-btn
><span v-if="jobActive">{{ progress }}</span>
</v-expansion-panel-content> </v-expansion-panel-content>
</v-expansion-panel> </v-expansion-panel>
</template> </template>
@@ -29,6 +38,8 @@ export default {
}, },
data: () => ({ data: () => ({
jobActive: false, jobActive: false,
currentJobId: null,
progress: "",
rights: window.$gz.role.defaultRightsObject(), rights: window.$gz.role.defaultRightsObject(),
available: false available: false
}), }),
@@ -51,6 +62,12 @@ export default {
canDoAction() { canDoAction() {
return true; return true;
}, },
async requestCancel() {
await window.$gz.api.upsert(
"job-operations/request-cancel",
this.currentJobId
);
},
async doAction() { async doAction() {
const vm = this; const vm = this;
const dialogResult = await window.$gz.dialog.confirmGeneric( const dialogResult = await window.$gz.dialog.confirmGeneric(
@@ -68,37 +85,39 @@ export default {
const body = this.dataListSelection; const body = this.dataListSelection;
try { try {
this.progress = "";
//call api route //call api route
let jobId = await window.$gz.api.upsert(url, body); let jobId = await window.$gz.api.upsert(url, body);
if (jobId.error) { if (jobId.error) {
throw new Error(window.$gz.errorHandler.errorToString(jobId, vm)); throw new Error(window.$gz.errorHandler.errorToString(jobId, vm));
} }
jobId = jobId.jobId; //it's in a sub key
//indicate loading by setting on button this.currentJobId = jobId.jobId;
vm.jobActive = true; vm.jobActive = true;
let jobStatus = 1; let jobProgress = {};
while (vm.jobActive == true) { while (vm.jobActive == true) {
await window.$gz.util.sleepAsync(1000); await window.$gz.util.sleepAsync(2000);
//check if done jobProgress = await window.$gz.api.get(
jobStatus = await window.$gz.api.get( `job-operations/progress/${this.currentJobId}`
`job-operations/status/${jobId}`
); );
if (jobStatus.error) { if (jobProgress.error) {
throw new Error( throw new Error(
window.$gz.errorHandler.errorToString(jobStatus, vm) window.$gz.errorHandler.errorToString(jobProgress, vm)
); );
} }
jobStatus = jobStatus.data; jobProgress = jobProgress.data;
if (jobStatus == 4 || jobStatus == 0) { this.progress = jobProgress.progress;
if (jobStatus == 4) {
if (jobProgress.jobStatus == 4 || jobProgress.jobStatus == 0) {
if (jobProgress.jobStatus == 4) {
//emit job id and event to parent for log viewing //emit job id and event to parent for log viewing
vm.$emit("ext-show-job-log", jobId); vm.$emit("ext-show-job-log", jobId);
} }
throw new Error("Job failed"); throw new Error("Job failed");
} }
if (jobStatus == 3) { if (jobProgress.jobStatus == 3) {
vm.jobActive = false; vm.jobActive = false;
} }
} }