feat(gateway): 创建/编辑网关后立即异步探活健康状态
- POST/PUT /api/gateways 成功后后台立即探活一次 /healthz 并覆盖落库,不阻塞请求 - probeAndRecordGateway 抽出单网关探活+落库复用;探活超时改为 var 供测试注入 - 网关页保存成功后延迟 2.5s 刷新一次,尽快展示最新健康状态 - 测试:立即探活、慢网关不阻塞、不可达落 unhealthy
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// 网关管理:语义对齐 web.archived GatewaysPage.jsx(注册/编辑 Modal、令牌显隐复制、删除)。
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { Alert, App, Button, Card, Flex, Form, Input, Modal, Popconfirm, Space, Table, Tag, Tooltip, Typography } from 'antd';
|
||||
import { CopyOutlined, EyeInvisibleOutlined, EyeOutlined, PlusOutlined } from '@ant-design/icons';
|
||||
import type { ColumnsType } from 'antd/es/table';
|
||||
@@ -96,6 +96,7 @@ export default function Page() {
|
||||
const [created, setCreated] = useState<any>(null);
|
||||
const { message: messageApi } = App.useApp();
|
||||
const { vertical, horizontal } = useOverflowGrid(gateways.length);
|
||||
const healthReloadTimer = useRef<ReturnType<typeof setTimeout>>(undefined);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setPending(true);
|
||||
@@ -110,6 +111,13 @@ export default function Page() {
|
||||
}
|
||||
}, []);
|
||||
|
||||
// 创建/编辑后的立即探活在后台异步进行:延迟刷新一次让健康状态列尽快显示最新结果。
|
||||
const scheduleHealthReload = useCallback(() => {
|
||||
clearTimeout(healthReloadTimer.current);
|
||||
healthReloadTimer.current = setTimeout(load, 2500);
|
||||
}, [load]);
|
||||
useEffect(() => () => clearTimeout(healthReloadTimer.current), []);
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, [load]);
|
||||
@@ -120,6 +128,7 @@ export default function Page() {
|
||||
const record = await create('gateways', values);
|
||||
setCreated(record?.data ?? record);
|
||||
await load();
|
||||
scheduleHealthReload();
|
||||
setCreateOpen(false);
|
||||
return true;
|
||||
} catch (reason) {
|
||||
@@ -136,6 +145,7 @@ export default function Page() {
|
||||
try {
|
||||
await update('gateways', editing.name, values);
|
||||
await load();
|
||||
scheduleHealthReload();
|
||||
setEditing(null);
|
||||
return true;
|
||||
} catch (reason) {
|
||||
|
||||
Reference in New Issue
Block a user