Reduce server console polling load
This commit is contained in:
@@ -62,9 +62,10 @@ const statusFilters: Array<{ id: ServerStatusFilter; label: string }> = [
|
||||
{ id: "attention", label: "需关注" }
|
||||
];
|
||||
|
||||
const serverListRefreshMs = 5000;
|
||||
const serverListRefreshMs = 15000;
|
||||
const serverMetricFreshMs = 30000;
|
||||
const serverForceDeleteConfirmation = "FORCE DELETE";
|
||||
const serverOperationalJobStates: JobResponse["state"][] = ["queued", "accepted", "running", "retrying", "failed"];
|
||||
|
||||
export function ServersPage({ session, operations, onNavigate }: PageComponentProps) {
|
||||
const [listState, setListState] = useState<ListState>("loading");
|
||||
@@ -93,16 +94,16 @@ export function ServersPage({ session, operations, onNavigate }: PageComponentPr
|
||||
if (showLoading) setListState("loading");
|
||||
try {
|
||||
const [pluginResponse, endpointResponse, instanceResponse, jobResponse] = await Promise.all([
|
||||
platformApiClient.listGamePlugins(),
|
||||
platformApiClient.listRunEndpoints(),
|
||||
showLoading ? platformApiClient.listGamePlugins() : Promise.resolve(undefined),
|
||||
platformApiClient.listRunEndpoints({ status: "online" }),
|
||||
platformApiClient.listServerInstances(),
|
||||
platformApiClient.listJobs()
|
||||
platformApiClient.listJobs(undefined, { states: serverOperationalJobStates })
|
||||
]);
|
||||
setPlugins(pluginResponse.items);
|
||||
if (pluginResponse) setPlugins(pluginResponse.items);
|
||||
setEndpoints(endpointResponse.items);
|
||||
setInstances(instanceResponse.items);
|
||||
setJobs(jobResponse.items);
|
||||
if (showLoading) setForm((current) => {
|
||||
if (showLoading && pluginResponse) setForm((current) => {
|
||||
const plugin = pluginResponse.items.find((item) => item.id === current.pluginId) ?? pluginResponse.items[0];
|
||||
return {
|
||||
...current,
|
||||
@@ -144,10 +145,14 @@ export function ServersPage({ session, operations, onNavigate }: PageComponentPr
|
||||
useEffect(() => {
|
||||
const timer = window.setInterval(() => {
|
||||
void refreshList(false);
|
||||
void refreshMetrics();
|
||||
}, serverListRefreshMs);
|
||||
return () => window.clearInterval(timer);
|
||||
}, [refreshList, refreshMetrics]);
|
||||
}, [refreshList]);
|
||||
|
||||
useEffect(() => {
|
||||
const timer = window.setInterval(() => void refreshMetrics(), serverMetricFreshMs);
|
||||
return () => window.clearInterval(timer);
|
||||
}, [refreshMetrics]);
|
||||
|
||||
const cards = useMemo<ServerCardView[]>(
|
||||
() =>
|
||||
|
||||
Reference in New Issue
Block a user