FIX - TASKER STARTUP: автовосстановление после запуска backend
This commit is contained in:
@@ -4,7 +4,16 @@
|
|||||||
* See the LICENSE file for details.
|
* See the LICENSE file for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function MaintenanceMessage() {
|
export type TMaintenanceReason = "starting" | "offline" | "unavailable";
|
||||||
|
|
||||||
|
type TMaintenanceMessageProps = {
|
||||||
|
autoRetry?: boolean;
|
||||||
|
reason?: TMaintenanceReason;
|
||||||
|
statusCode?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function MaintenanceMessage(props: TMaintenanceMessageProps) {
|
||||||
|
const { autoRetry = false, reason = "unavailable", statusCode } = props;
|
||||||
const linkMap = [
|
const linkMap = [
|
||||||
{
|
{
|
||||||
key: "mail_to",
|
key: "mail_to",
|
||||||
@@ -13,24 +22,33 @@ export function MaintenanceMessage() {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const title =
|
||||||
|
reason === "starting"
|
||||||
|
? "Сервисы NODE.DC запускаются."
|
||||||
|
: reason === "offline"
|
||||||
|
? "Нет связи с сервером NODE.DC."
|
||||||
|
: "NODE.DC временно недоступен.";
|
||||||
|
|
||||||
|
const description =
|
||||||
|
reason === "starting"
|
||||||
|
? "Сервер ещё не готов после обновления или перезапуска. NODE.DC подключится автоматически сразу после завершения запуска. Перезагружать страницу не нужно."
|
||||||
|
: reason === "offline"
|
||||||
|
? "Не удалось связаться с сервером. NODE.DC проверяет подключение автоматически и продолжит работу после восстановления связи."
|
||||||
|
: autoRetry
|
||||||
|
? "Сервер временно не может обработать запрос. NODE.DC повторяет подключение автоматически и продолжит работу после восстановления."
|
||||||
|
: "Сервер вернул ошибку, которую нельзя исправить автоматическим повтором. Попробуйте ещё раз или обратитесь в службу поддержки.";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="flex flex-col gap-2.5">
|
<div className="flex flex-col gap-2.5">
|
||||||
<h1 className="text-left text-18 font-semibold text-primary">🚧 NODE.DC запустился с ошибкой.</h1>
|
<h1 className="text-left text-18 font-semibold text-primary">🚧 {title}</h1>
|
||||||
<span className="text-left text-14 font-medium text-secondary">
|
<span className="text-left text-14 font-medium text-secondary">{description}</span>
|
||||||
Часть сервисов могла не подняться. Проверьте логи контейнеров и устраните причину. Если нужна помощь,
|
{statusCode && <span className="text-left text-12 text-tertiary">Код ответа сервера: {statusCode}</span>}
|
||||||
переходите в службу поддержки.
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-1 flex items-center justify-start gap-6">
|
<div className="mt-1 flex items-center justify-start gap-6">
|
||||||
{linkMap.map((link) => (
|
{linkMap.map((link) => (
|
||||||
<div key={link.key}>
|
<div key={link.key}>
|
||||||
<a
|
<a href={link.value} target="_blank" rel="noopener noreferrer" className="nodedc-error-link text-13">
|
||||||
href={link.value}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className="nodedc-error-link text-13"
|
|
||||||
>
|
|
||||||
{link.label}
|
{link.label}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { useTheme } from "next-themes";
|
import { useTheme } from "next-themes";
|
||||||
|
import { Button } from "@plane/propel/button";
|
||||||
// assets
|
// assets
|
||||||
import maintenanceModeDarkModeImage from "@/app/assets/instance/maintenance-mode-dark.svg?url";
|
import maintenanceModeDarkModeImage from "@/app/assets/instance/maintenance-mode-dark.svg?url";
|
||||||
import maintenanceModeLightModeImage from "@/app/assets/instance/maintenance-mode-light.svg?url";
|
import maintenanceModeLightModeImage from "@/app/assets/instance/maintenance-mode-light.svg?url";
|
||||||
@@ -12,8 +13,18 @@ import maintenanceModeLightModeImage from "@/app/assets/instance/maintenance-mod
|
|||||||
import DefaultLayout from "@/layouts/default-layout";
|
import DefaultLayout from "@/layouts/default-layout";
|
||||||
// components
|
// components
|
||||||
import { MaintenanceMessage } from "@/plane-web/components/instance";
|
import { MaintenanceMessage } from "@/plane-web/components/instance";
|
||||||
|
import type { TMaintenanceReason } from "@/plane-web/components/instance";
|
||||||
|
|
||||||
export function MaintenanceView() {
|
type TMaintenanceViewProps = {
|
||||||
|
autoRetry?: boolean;
|
||||||
|
isRetrying?: boolean;
|
||||||
|
reason?: TMaintenanceReason;
|
||||||
|
statusCode?: number;
|
||||||
|
onRetry?: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function MaintenanceView(props: TMaintenanceViewProps) {
|
||||||
|
const { autoRetry = false, isRetrying = false, reason = "unavailable", statusCode, onRetry } = props;
|
||||||
// hooks
|
// hooks
|
||||||
const { resolvedTheme } = useTheme();
|
const { resolvedTheme } = useTheme();
|
||||||
// derived values
|
// derived values
|
||||||
@@ -31,7 +42,20 @@ export function MaintenanceView() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="relative mt-4 flex w-full flex-col gap-4">
|
<div className="relative mt-4 flex w-full flex-col gap-4">
|
||||||
<MaintenanceMessage />
|
<MaintenanceMessage autoRetry={autoRetry} reason={reason} statusCode={statusCode} />
|
||||||
|
{onRetry && (
|
||||||
|
<div className="flex justify-start">
|
||||||
|
<Button
|
||||||
|
variant="primary"
|
||||||
|
size="lg"
|
||||||
|
className="nodedc-error-primary"
|
||||||
|
loading={isRetrying}
|
||||||
|
onClick={onRetry}
|
||||||
|
>
|
||||||
|
Проверить сейчас
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</DefaultLayout>
|
</DefaultLayout>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import type { ReactNode } from "react";
|
import type { ReactNode } from "react";
|
||||||
|
import { isAxiosError } from "axios";
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
// components
|
// components
|
||||||
@@ -17,16 +18,44 @@ type TInstanceWrapper = {
|
|||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const INSTANCE_RETRY_BASE_INTERVAL = 2_000;
|
||||||
|
const INSTANCE_RETRY_MAX_INTERVAL = 30_000;
|
||||||
|
|
||||||
|
export const getInstanceRetryInterval = (retryCount: number) =>
|
||||||
|
Math.min(INSTANCE_RETRY_MAX_INTERVAL, INSTANCE_RETRY_BASE_INTERVAL * 2 ** Math.min(Math.max(retryCount - 1, 0), 4));
|
||||||
|
|
||||||
|
export const getInstanceErrorStatus = (error: unknown) => (isAxiosError(error) ? error.response?.status : undefined);
|
||||||
|
|
||||||
|
export const shouldRetryInstanceRequest = (error: unknown) => {
|
||||||
|
if (!isAxiosError(error) || !error.response) return true;
|
||||||
|
|
||||||
|
const { status } = error.response;
|
||||||
|
return status === 408 || status === 429 || status >= 500;
|
||||||
|
};
|
||||||
|
|
||||||
const InstanceWrapper = observer(function InstanceWrapper(props: TInstanceWrapper) {
|
const InstanceWrapper = observer(function InstanceWrapper(props: TInstanceWrapper) {
|
||||||
const { children } = props;
|
const { children } = props;
|
||||||
// store
|
// store
|
||||||
const { isLoading, instance, error, fetchInstanceInfo } = useInstance();
|
const { isLoading, instance, error, fetchInstanceInfo } = useInstance();
|
||||||
|
|
||||||
const { isLoading: isInstanceSWRLoading, error: instanceSWRError } = useSWR(
|
const {
|
||||||
"INSTANCE_INFORMATION",
|
isLoading: isInstanceSWRLoading,
|
||||||
async () => await fetchInstanceInfo(),
|
isValidating: isInstanceSWRValidating,
|
||||||
{ revalidateOnFocus: false }
|
error: instanceSWRError,
|
||||||
);
|
mutate: retryInstanceInfo,
|
||||||
|
} = useSWR("INSTANCE_INFORMATION", async () => await fetchInstanceInfo(), {
|
||||||
|
revalidateOnFocus: true,
|
||||||
|
revalidateOnReconnect: true,
|
||||||
|
shouldRetryOnError: true,
|
||||||
|
onErrorRetry: (requestError, _key, _config, revalidate, { retryCount }) => {
|
||||||
|
if (typeof navigator !== "undefined" && !navigator.onLine) return;
|
||||||
|
if (!shouldRetryInstanceRequest(requestError)) return;
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
void revalidate({ retryCount });
|
||||||
|
}, getInstanceRetryInterval(retryCount));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// loading state
|
// loading state
|
||||||
if ((isLoading || isInstanceSWRLoading) && !instance)
|
if ((isLoading || isInstanceSWRLoading) && !instance)
|
||||||
@@ -36,7 +65,27 @@ const InstanceWrapper = observer(function InstanceWrapper(props: TInstanceWrappe
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
if (instanceSWRError) return <MaintenanceView />;
|
if (instanceSWRError) {
|
||||||
|
const statusCode = getInstanceErrorStatus(instanceSWRError);
|
||||||
|
const reason =
|
||||||
|
statusCode === 502 || statusCode === 503 || statusCode === 504
|
||||||
|
? "starting"
|
||||||
|
: statusCode === undefined
|
||||||
|
? "offline"
|
||||||
|
: "unavailable";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<MaintenanceView
|
||||||
|
autoRetry={shouldRetryInstanceRequest(instanceSWRError)}
|
||||||
|
isRetrying={isInstanceSWRValidating}
|
||||||
|
reason={reason}
|
||||||
|
statusCode={statusCode}
|
||||||
|
onRetry={() => {
|
||||||
|
void retryInstanceInfo();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// something went wrong while in the request
|
// something went wrong while in the request
|
||||||
if (error && error?.status === "error") return <>{children}</>;
|
if (error && error?.status === "error") return <>{children}</>;
|
||||||
|
|||||||
Reference in New Issue
Block a user