Skip to content

Commit

Permalink
feat: change re-sync scenario (#5064)
Browse files Browse the repository at this point in the history
* feat: change re-sync scenario

Signed-off-by: NaYeong,Kim <[email protected]>

* chore: update translations

Signed-off-by: NaYeong,Kim <[email protected]>

* fix: update logic for checking in-progress tasks

Signed-off-by: NaYeong,Kim <[email protected]>

---------

Signed-off-by: NaYeong,Kim <[email protected]>
  • Loading branch information
skdud4659 authored Nov 20, 2024
1 parent 0c8a813 commit 7832c56
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import {
computed, onMounted, onUnmounted, reactive, watch,
} from 'vue';
import dayjs from 'dayjs';
import { makeDistinctValueHandler } from '@cloudforet/core-lib/component-util/query-search';
import { getApiQueryWithToolboxOptions } from '@cloudforet/core-lib/component-util/toolbox';
import type { ConsoleFilter } from '@cloudforet/core-lib/query/type';
Expand All @@ -17,7 +15,6 @@ import type { KeyItemSet, ValueHandlerMap } from '@cloudforet/mirinae/types/cont
import type { ToolboxOptions } from '@cloudforet/mirinae/types/controls/toolbox/type';
import type { CostJobStatus } from '@/schema/cost-analysis/job/type';
import { store } from '@/store';
import { i18n } from '@/translations';
import { useQueryTags } from '@/common/composables/query-tags';
Expand All @@ -44,15 +41,14 @@ const storeState = reactive({
totalCount: computed<number>(() => dataSourcesPageState.jobListTotalCount),
activeTab: computed<string>(() => dataSourcesPageState.activeTab),
selectedDataSourceItem: computed<DataSourceItem>(() => dataSourcesPageGetters.selectedDataSourceItem),
recentJobItem: computed<CostJobItem>(() => dataSourcesPageGetters.jobList[0]),
timezone: computed<string>(() => store.state.user.timezone),
});
const state = reactive({
loading: false,
modalVisible: false,
modalType: '' as DataCollectionHistoryModalType,
selectedJobId: '',
selectedJobItem: computed<CostJobItem|undefined>(() => storeState.jobList.find((item) => item.job_id === state.selectedJobId)),
hasInProgressItem: computed<boolean>(() => storeState.jobList.some((item) => item.status === 'IN_PROGRESS')),
});
const tableState = reactive({
pageStart: 0,
Expand Down Expand Up @@ -163,11 +159,8 @@ const handleClickErrorDetail = (jobId: string) => {
};
const handleClickResyncButton = () => {
state.modalVisible = true;
const createdDate = dayjs.tz(storeState.recentJobItem.created_at, storeState.timezone);
const now = dayjs().tz(storeState.timezone);
const diffInMinutes = now.diff(createdDate, 'minute');
// NOTE: If a task is restarted within 10 minutes of the last task's start time, the restarted task may be canceled.
state.modalType = (storeState.recentJobItem.status === 'IN_PROGRESS' && diffInMinutes < 10) ? 'RESTART' : 'RE-SYNC';
// NOTE: If the latest job is in progress, it can be canceled and restarted only if 10 minutes have passed since the start time.
state.modalType = state.hasInProgressItem ? 'RESTART' : 'RE-SYNC';
};
const handleSelectStatus = (selected: string) => {
tableState.selectedStatusFilter = selected;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
PButtonModal, PTextEditor, PFieldTitle, PToggleButton, PTextInput, PDatetimePicker, PScopedNotification,
} from '@cloudforet/mirinae';
import { store } from '@/store';
import { i18n } from '@/translations';
import { useProxyValue } from '@/common/composables/proxy-state';
Expand Down Expand Up @@ -41,6 +42,8 @@ const emit = defineEmits<{(e: 'update:modal-visible'): void,
const storeState = reactive({
selectedDataSourceItem: computed<DataSourceItem>(() => dataSourcesPageGetters.selectedDataSourceItem),
jobList: computed<CostJobItem[]>(() => dataSourcesPageGetters.jobList),
timezone: computed<string>(() => store.state.user.timezone),
});
const state = reactive({
proxyVisible: useProxyValue('modalVisible', props, emit),
Expand Down Expand Up @@ -77,6 +80,13 @@ const state = reactive({
}
return false;
}),
diffInMinutes: computed<number>(() => {
const recentJobItem = storeState.jobList.filter((i) => i.status === 'IN_PROGRESS')[0];
const createdDate = dayjs.tz(recentJobItem.created_at, storeState.timezone);
const now = dayjs().tz(storeState.timezone);
return now.diff(createdDate, 'minute');
}),
hasInProgressItem: computed<boolean>(() => storeState.jobList.some((item) => item.status === 'IN_PROGRESS')),
});
const handleUpdateSelectedDates = (selectedDates: string[]) => {
Expand All @@ -91,18 +101,31 @@ const handleChangeToggleButton = () => {
const handleConfirmButton = async () => {
try {
state.loading = true;
if (props.modalType === 'ERROR') return;
if (props.modalType === 'RE-SYNC' || props.modalType === 'RESTART') {
switch (props.modalType) {
case 'ERROR':
return;
case 'RE-SYNC':
case 'RESTART':
if (state.hasInProgressItem && state.diffInMinutes <= 10) return;
await dataSourcesPageStore.fetchSyncDatasource({
start: state.toggleValue ? undefined : dayjs(state.startDates[0]).format('YYYY-MM'),
data_source_id: storeState.selectedDataSourceItem.data_source_id,
});
break;
case 'CANCEL':
if (props.selectedJobItem) {
await dataSourcesPageStore.fetchCancelJob({
job_id: props.selectedJobItem?.job_id,
});
}
break;
default: break;
}
if (props.modalType === 'CANCEL' && props.selectedJobItem) {
await dataSourcesPageStore.fetchCancelJob({
job_id: props.selectedJobItem?.job_id,
});
}
await emit('confirm');
} finally {
state.loading = false;
Expand All @@ -120,6 +143,7 @@ const handleConfirmButton = async () => {
backdrop
:loading="state.loading"
:disabled="state.modalValidation"
:hide-footer-close-button="props.modalType === 'RESTART' && state.hasInProgressItem && state.diffInMinutes <= 10"
:theme-color="props.modalType === 'CANCEL' || props.modalType === 'RESTART' ? 'alert' : 'primary'"
:visible.sync="state.proxyVisible"
class="data-source-management-tab-data-collection-history-modal"
Expand All @@ -140,8 +164,13 @@ const handleConfirmButton = async () => {
<div v-else
class="content-inner"
>
<b class="desc-title">{{ $t('BILLING.COST_MANAGEMENT.DATA_SOURCES.RESTART_MODAL_DESC_1') }}</b>
<p>{{ $t('BILLING.COST_MANAGEMENT.DATA_SOURCES.RESTART_MODAL_DESC_2') }}</p>
<div v-if="state.diffInMinutes > 10">
<b class="desc-title">{{ $t('BILLING.COST_MANAGEMENT.DATA_SOURCES.RESTART_MODAL_DESC_1') }}</b>
<p>{{ $t('BILLING.COST_MANAGEMENT.DATA_SOURCES.RESTART_MODAL_DESC_2') }}</p>
</div>
<div v-else>
<p>{{ $t('BILLING.COST_MANAGEMENT.DATA_SOURCES.RESTART_MODAL_CANCEL_DESC') }}</p>
</div>
</div>
</p-scoped-notification>
</div>
Expand Down Expand Up @@ -204,10 +233,15 @@ const handleConfirmButton = async () => {
<template #confirm-button>
<span v-if="props.modalType === 'ERROR'">{{ $t('BILLING.COST_MANAGEMENT.DATA_SOURCES.ERROR_FOUND_OK') }}</span>
<span v-else-if="props.modalType === 'CANCEL'">{{ $t('BILLING.COST_MANAGEMENT.DATA_SOURCES.CANCEL_BUTTON') }}</span>
<span v-else-if="props.modalType === 'RESTART'">{{ $t('BILLING.COST_MANAGEMENT.DATA_SOURCES.RESTART_MODAL_BUTTON') }}</span>
<span v-else-if="props.modalType === 'RESTART'
&& state.hasInProgressItem
&& state.diffInMinutes > 10"
>
{{ $t('BILLING.COST_MANAGEMENT.DATA_SOURCES.RESTART_MODAL_BUTTON') }}
</span>
</template>
<template #close-button>
<span v-if="props.modalType === 'RESTART' || props.modalType === 'CANCEL'">{{ $t('BILLING.COST_MANAGEMENT.DATA_SOURCES.KEEP_COLLECTING') }}</span>
<span v-if="props.modalType === 'CANCEL'">{{ $t('BILLING.COST_MANAGEMENT.DATA_SOURCES.KEEP_COLLECTING') }}</span>
</template>
</p-button-modal>
</template>
Expand Down
21 changes: 21 additions & 0 deletions packages/language-pack/console-translation-2.8.babel
Original file line number Diff line number Diff line change
Expand Up @@ -17191,6 +17191,27 @@
</translation>
</translations>
</concept_node>
<concept_node>
<name>RESTART_MODAL_CANCEL_DESC</name>
<definition_loaded>false</definition_loaded>
<description/>
<comment/>
<default_text/>
<translations>
<translation>
<language>en-US</language>
<approved>true</approved>
</translation>
<translation>
<language>ja-JP</language>
<approved>true</approved>
</translation>
<translation>
<language>ko-KR</language>
<approved>true</approved>
</translation>
</translations>
</concept_node>
<concept_node>
<name>RESTART_MODAL_DESC_1</name>
<definition_loaded>false</definition_loaded>
Expand Down
1 change: 1 addition & 0 deletions packages/language-pack/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,7 @@
"RESETTING": "Resetting...",
"RESET_MODAL_TITLE": "Are you sure you want to reset workspaces for {count} linked accounts?",
"RESTART_MODAL_BUTTON": "Cancel and Re-start",
"RESTART_MODAL_CANCEL_DESC": "Data Collecting is still in progress.\nIf you want to re-sync, cancel the in progress job and proceed with the re-sync.",
"RESTART_MODAL_DESC_1": "Data collection is still in progress.",
"RESTART_MODAL_DESC_2": "Canceling the current data collection job may result in a delay when restarting the process. This action cannot be undone.",
"RESTART_MODAL_TITLE": "Do you want to cancel and re-start it?",
Expand Down
1 change: 1 addition & 0 deletions packages/language-pack/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,7 @@
"RESETTING": "リセット中...",
"RESET_MODAL_TITLE": "ワークスペースに連携された{count}個のアカウントを初期化しますか?",
"RESTART_MODAL_BUTTON": "",
"RESTART_MODAL_CANCEL_DESC": "データ収集が進行中です。\n再同期を希望する場合は、進行中の作業をキャンセルしてから再同期を行ってください。",
"RESTART_MODAL_DESC_1": "",
"RESTART_MODAL_DESC_2": "",
"RESTART_MODAL_TITLE": "",
Expand Down
1 change: 1 addition & 0 deletions packages/language-pack/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,7 @@
"RESETTING": "초기화 중...",
"RESET_MODAL_TITLE": "워크스페이스에 연결된 {count}개 계정을 초기화하시겠습니까?",
"RESTART_MODAL_BUTTON": "",
"RESTART_MODAL_CANCEL_DESC": "데이터 수집이 진행 중입니다.\n동기화를 원하실 경우, 진행 중인 작업을 먼저 취소하고 동기화를 진행하세요.",
"RESTART_MODAL_DESC_1": "",
"RESTART_MODAL_DESC_2": "",
"RESTART_MODAL_TITLE": "",
Expand Down

0 comments on commit 7832c56

Please sign in to comment.