This commit is contained in:
2022-09-28 00:07:03 +00:00
parent 2da288f2ce
commit 040ff001d8

View File

@@ -37,6 +37,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>
@@ -50,6 +59,8 @@ export default {
tag: null, tag: null,
replace: null, replace: null,
jobActive: false, jobActive: false,
currentJobId: null,
progress: "",
rights: window.$gz.role.defaultRightsObject(), rights: window.$gz.role.defaultRightsObject(),
available: false available: false
}), }),
@@ -78,6 +89,12 @@ export default {
} }
return false; return false;
}, },
async requestCancel() {
await window.$gz.api.upsert(
"job-operations/request-cancel",
this.currentJobId
);
},
async doAction() { async doAction() {
let url = "tag-list/"; let url = "tag-list/";
switch (this.action) { switch (this.action) {
@@ -93,29 +110,34 @@ export default {
} }
try { try {
this.progress = "";
let jobId = await window.$gz.api.upsert(url, this.dataListSelection); let jobId = await window.$gz.api.upsert(url, this.dataListSelection);
if (jobId.error) { if (jobId.error) {
throw new Error(window.$gz.errorHandler.errorToString(jobId, this)); throw new Error(window.$gz.errorHandler.errorToString(jobId, this));
} }
jobId = jobId.jobId;
this.currentJobId = jobId.jobId;
this.jobActive = true; this.jobActive = true;
let jobStatus = 1; let jobProgress = {};
while (this.jobActive == true) { while (this.jobActive == true) {
await window.$gz.util.sleepAsync(1000); await window.$gz.util.sleepAsync(2000);
jobStatus = await window.$gz.api.get( jobProgress = await window.$gz.api.get(
`job-operations/status/${jobId}` `job-operations/progress/${this.currentJobId}`
); );
if (jobStatus.error) {
if (jobProgress.error) {
throw new Error( throw new Error(
window.$gz.errorHandler.errorToString(jobStatus, this) window.$gz.errorHandler.errorToString(jobProgress, this)
); );
} }
jobStatus = jobStatus.data; jobProgress = jobProgress.data;
if (jobStatus == 4 || jobStatus == 0) { this.progress = jobProgress.progress;
if (jobProgress.jobStatus == 4 || jobProgress.jobStatus == 0) {
throw new Error("Job failed"); throw new Error("Job failed");
} }
if (jobStatus == 3) { if (jobProgress.jobStatus == 3) {
this.jobActive = false; this.jobActive = false;
} }
} }