From b4b6bbd1122a3de8a25f325fe642424a03583699 Mon Sep 17 00:00:00 2001 From: agatha197 Date: Wed, 6 Nov 2024 14:45:35 +0900 Subject: [PATCH] feat: batch session timeout --- react/src/pages/SessionLauncherPage.tsx | 185 ++++++++++++++++++++++++ resources/i18n/de.json | 18 ++- resources/i18n/el.json | 18 ++- resources/i18n/en.json | 18 ++- resources/i18n/es.json | 18 ++- resources/i18n/fi.json | 18 ++- resources/i18n/fr.json | 18 ++- resources/i18n/id.json | 18 ++- resources/i18n/it.json | 18 ++- resources/i18n/ja.json | 18 ++- resources/i18n/ko.json | 18 ++- resources/i18n/mn.json | 18 ++- resources/i18n/ms.json | 18 ++- resources/i18n/pl.json | 18 ++- resources/i18n/pt-BR.json | 18 ++- resources/i18n/pt.json | 18 ++- resources/i18n/ru.json | 18 ++- resources/i18n/th.json | 18 ++- resources/i18n/tr.json | 19 ++- resources/i18n/vi.json | 18 ++- resources/i18n/zh-CN.json | 18 ++- resources/i18n/zh-TW.json | 18 ++- src/lib/backend.ai-client-esm.ts | 4 + 23 files changed, 506 insertions(+), 62 deletions(-) diff --git a/react/src/pages/SessionLauncherPage.tsx b/react/src/pages/SessionLauncherPage.tsx index f2b465859..07167bfe5 100644 --- a/react/src/pages/SessionLauncherPage.tsx +++ b/react/src/pages/SessionLauncherPage.tsx @@ -133,6 +133,7 @@ interface SessionConfig { startupCommand?: string; bootstrap_script?: string; agent_list?: string[]; + batch_timeout?: string; } interface CreateSessionInfo { @@ -148,6 +149,9 @@ interface SessionLauncherValue { enabled: boolean; scheduleDate?: string; command?: string; + timeoutEnabled?: boolean; + timeout?: string; + timeoutUnit?: string; }; allocationPreset: string; envvars: EnvVarFormListValue[]; @@ -192,6 +196,7 @@ const SessionLauncherPage = () => { const supportExtendedImageInfo = baiClient?.supports('extended-image-info') ?? false; + const supportBatchTimeout = baiClient?.supports('batch-timeout') ?? false; const [isStartingSession, setIsStartingSession] = useState(false); const INITIAL_FORM_VALUES: DeepPartial = useMemo( @@ -208,6 +213,11 @@ const SessionLauncherPage = () => { enabled: false, command: undefined, scheduleDate: undefined, + ...(supportBatchTimeout && { + timeoutEnabled: false, + timeout: undefined, + timeoutUnit: 's', + }), }, envvars: [], // set default_session_environment only if set @@ -222,6 +232,7 @@ const SessionLauncherPage = () => { [ baiClient._config?.default_session_environment, currentGlobalResourceGroup, + supportBatchTimeout, ], ); const StepParam = withDefault(NumberParam, 0); @@ -515,6 +526,15 @@ const SessionLauncherPage = () => { ), } // Filter out undefined values : undefined), + ...(supportBatchTimeout && + values?.batch?.timeoutEnabled && + !_.isUndefined(values?.batch?.timeout) + ? { + batch_timeout: + _.toString(values.batch.timeout) + + values?.batch?.timeoutUnit, + } + : undefined), }, }; const sessionPromises = _.map( @@ -979,6 +999,150 @@ const SessionLauncherPage = () => { + {supportBatchTimeout ? ( + + + {t('session.launcher.BatchJobTimeoutDuration')} + + + + + + } + extra={ + + prev.batch.timeout !== next.batch.timeout || + prev.batch.timeoutUnit !== next.batch.timeoutUnit + } + > + {() => { + const timeout = form.getFieldValue([ + 'batch', + 'timeout', + ]); + const unit = form.getFieldValue([ + 'batch', + 'timeoutUnit', + ]); + const humanizedDuration = timeout + ? dayjs + .duration(timeout, unit ?? 'ms') + .humanize(true) + : null; + return !_.isNull(timeout) && + _.toFinite(timeout) > 0 + ? humanizedDuration + : null; + }} + + } + > + + + { + if (e.target.checked === false) { + form.setFieldValue( + ['batch', 'timeout'], + undefined, + ); + } + form.validateFields([['batch', 'timeout']]); + }} + > + {t('session.launcher.Enable')} + + + { + return ( + prev.batch?.timeoutEnabled !== + next.batch?.timeoutEnabled + ); + }} + > + {() => { + const disabled = + form.getFieldValue([ + 'batch', + 'timeoutEnabled', + ]) !== true; + return ( + <> + + +