Skip to content

Commit

Permalink
feat: delete uncompleted file if the task failed in the middle of pro…
Browse files Browse the repository at this point in the history
…gress

Signed-off-by: seven <[email protected]>
  • Loading branch information
Blankll committed Nov 17, 2024
1 parent 2ca9fc0 commit b245aa6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/store/backupRestoreStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ export const useBackupRestoreStore = defineStore('backupRestoreStore', {
}),
);

console.log('es response', response);

const hits = response.hits.hits;
if (hits.length === 0) {
hasMore = false;
Expand All @@ -67,6 +65,7 @@ export const useBackupRestoreStore = defineStore('backupRestoreStore', {
}
return filePath;
} catch (error) {
sourceFileApi.deleteFileOrFolder(filePath).catch();
throw new CustomError(
get(error, 'status', 500),
get(error, 'details', get(error, 'message', '')),
Expand Down
12 changes: 11 additions & 1 deletion src/store/connectionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ export const useConnectionStore = defineStore('connectionStore', {
establishedIndexOptions(state) {
return state.established?.indices.map(({ index }) => ({ label: index, value: index })) ?? [];
},
connectionOptions(state) {
return state.connections.map(({ name }) => ({ label: name, value: name }));
},
},
actions: {
async fetchConnections() {
Expand All @@ -96,8 +99,15 @@ export const useConnectionStore = defineStore('connectionStore', {
await storeApi.set('connections', pureObject(this.connections));
},
async establishConnection(connection: Connection) {
await this.testConnection(connection);
try {
await this.testConnection(connection);
} catch (err) {
this.established = null;
throw err;
}

const client = loadHttpClient(connection);

try {
const data = (await client.get('/_cat/indices', 'format=json')) as Array<{
[key: string]: string;
Expand Down
30 changes: 18 additions & 12 deletions src/views/backup-restore/components/backup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<n-grid-item span="8">
<n-form-item :label="$t('backup.backupForm.index')" path="index">
<n-select
:options="establishedIndexOptions"
:options="indexOptions"
:placeholder="$t('connection.selectIndex')"
v-model:value="backupFormData.index"
remote
Expand Down Expand Up @@ -114,13 +114,7 @@ const message = useMessage();
const lang = useLang();
const fileFormRef = ref();
const connectionStore = useConnectionStore();
const {
fetchConnections,
fetchIndices,
establishConnection,
selectIndex,
establishedIndexOptions,
} = connectionStore;
const { fetchConnections, fetchIndices, establishConnection, selectIndex } = connectionStore;
const { established, connections } = storeToRefs(connectionStore);
const backupRestoreStore = useBackupRestoreStore();
Expand Down Expand Up @@ -180,15 +174,27 @@ const backupFormRules = reactive<FormRules>({
// },
// ],
});
const loadingRefs = ref<{ connection: boolean; index: boolean }>({
connection: false,
index: false,
});
const connectionOptions = computed(() =>
connections.value.map(({ name }) => ({ label: name, value: name })),
);
const indexOptions = ref<Array<{ label: string; value: string }>>([]);
watch(established, () => {
if (!established.value) {
indexOptions.value = [];
backupFormData.value.index = '';
return;
}
indexOptions.value =
established.value?.indices.map(({ index }) => ({ label: index, value: index })) ?? [];
});
const loadingRefs = ref<{ connection: boolean; index: boolean }>({
connection: false,
index: false,
});
const handleOpen = async (isOpen: boolean, target: string) => {
if (!isOpen) return;
if (target === 'connection') {
Expand Down

0 comments on commit b245aa6

Please sign in to comment.