Skip to content

Commit

Permalink
lock backup/restore button until job finishes or
Browse files Browse the repository at this point in the history
job options change
prevents starting duplicate backup/restore jobs
refs: #572
  • Loading branch information
eug3nix committed Jan 7, 2025
1 parent b4fd26b commit b10cefd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
27 changes: 21 additions & 6 deletions pgmanage/app/static/pgmanage_frontend/src/components/BackupTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,12 @@
<div class="btn-group">
<a data-testid="preview-button" :class="['btn', 'btn-outline-primary', 'mb-2', { 'disabled': !backupOptions.fileName}]"
@click="previewCommand">Preview</a>
<a data-testid="backup-button" :class="['btn', 'btn-success', 'mb-2', 'ms-0', { 'disabled': !backupOptions.fileName }]"
<a data-testid="backup-button" :class="['btn', 'btn-success', 'mb-2', 'ms-0', { 'disabled': !backupOptions.fileName || backupLocked }]"
@click.prevent="saveBackup">Backup</a>
</div>
</div>
</form>
<UtilityJobs ref="jobs" />
<UtilityJobs @jobExit="handleJobExit" ref="jobs" />

</div>
</template>
Expand Down Expand Up @@ -384,7 +384,9 @@ export default {
pigz_compression_ratio: "6"
},
backupOptions: {},
backupTabId: this.tabId
backupTabId: this.tabId,
backupLocked: false,
lastJobId: 0
}
},
computed: {
Expand Down Expand Up @@ -486,7 +488,13 @@ export default {
this.backupOptions.fileName += '.tar';
break;
}
}
},
backupOptions: {
handler() {
this.backupLocked = false;
},
deep: true
},
},
methods: {
getRoleNames() {
Expand All @@ -502,17 +510,20 @@ export default {
})
},
saveBackup() {
this.backupLocked = true;
axios.post("/backup/", {
database_index: this.databaseIndex,
workspaceId: this.workspaceId,
data: this.backupOptions,
backup_type: this.type
})
.then((resp) => {
this.$refs.jobs.startJob(resp.data.job_id, resp.data.description)
this.$refs.jobs.startJob(resp.data.job_id, resp.data.description);
this.lastJobId = resp.data.job_id;
})
.catch((error) => {
showToast("error", error.response.data.data)
showToast("error", error.response.data.data);
this.backupLocked = false;
})
},
onFile(e) {
Expand Down Expand Up @@ -554,6 +565,10 @@ export default {
.catch((error) => {
showToast("error", error.response.data.data)
})
},
handleJobExit(jobId) {
if(jobId === this.lastJobId)
this.backupLocked = false;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@
<div class="btn-group" role="group">
<a data-testid="preview-button" :class="['btn', 'btn-outline-primary', 'mb-2', { 'disabled': !restoreOptions.fileName }]"
@click="previewCommand">Preview</a>
<a data-testid="restore-button" :class="['btn', 'btn-success', 'mb-2', { 'disabled': !restoreOptions.fileName }]"
<a data-testid="restore-button" :class="['btn', 'btn-success', 'mb-2', { 'disabled': !restoreOptions.fileName || restoreLocked }]"
@click.prevent="createRestore">Restore</a>
</div>
</div>
</form>
<UtilityJobs ref="jobs" />
<UtilityJobs @jobExit="handleJobExit" ref="jobs" />
</div>
</template>

Expand Down Expand Up @@ -312,7 +312,9 @@ export default {
pigz_number_of_jobs: 'auto',
},
restoreOptions: {},
restoreTabId: this.tabId
restoreTabId: this.tabId,
restoreLocked: false,
lastJobId: 0
}
},
computed: {
Expand Down Expand Up @@ -343,7 +345,13 @@ export default {
if (newValue === 'directory') {
this.restoreOptions.pigz = false
}
}
},
restoreOptions: {
handler() {
this.restoreLocked = false;
},
deep: true
},
},
mounted() {
this.$nextTick(() => {
Expand Down Expand Up @@ -382,16 +390,19 @@ export default {
})
},
createRestore() {
this.restoreLocked = true;
axios.post("/restore/", {
database_index: this.databaseIndex,
workspace_id: this.workspaceId,
data: this.restoreOptions
})
.then((resp) => {
this.$refs.jobs.startJob(resp.data.job_id, resp.data.description)
this.lastJobId = resp.data.job_id;
})
.catch((error) => {
showToast("error", error.response.data.data)
showToast("error", error.response.data.data);
this.restoreLocked = false;
})
},
onFile(e) {
Expand Down Expand Up @@ -419,6 +430,10 @@ export default {
.catch((error) => {
showToast("error", error.response.data.data)
})
},
handleJobExit(jobId) {
if(jobId === this.lastJobId)
this.restoreLocked = false;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export default {
unmounted() {
clearInterval(this.workerId);
},
emits: ['jobExit'],
methods: {
getJobList() {
axios
Expand Down Expand Up @@ -183,6 +184,7 @@ export default {
this.pendingJobId = this.pendingJobId.filter((id) => {
if (completedJobIds.includes(id)) {
let j = this.jobList.find((j) => j.id == id);
this.$emit('jobExit', id)
if (j.process_state != JobState.PROCESS_TERMINATED)
this.sendNotifyJobFinished(j.description, j.process_state, () =>
this.getJobDetails(j.id, event)
Expand Down

0 comments on commit b10cefd

Please sign in to comment.