Reduce hot run polling pressure
This commit is contained in:
@@ -323,6 +323,9 @@ describe("PlatformApiClient AI providers", () => {
|
||||
if (url.endsWith("/api/v1/jobs?states=queued%2Crunning%2Cfailed")) {
|
||||
return jsonResponse({ items: [job], count: 1 });
|
||||
}
|
||||
if (url.endsWith("/api/v1/jobs?states=queued%2Crunning%2Cfailed&limit=25")) {
|
||||
return jsonResponse({ items: [job], count: 1 });
|
||||
}
|
||||
if (url.endsWith("/api/v1/jobs?serverInstanceId=server-1&states=queued%2Crunning%2Cfailed")) {
|
||||
return jsonResponse({ items: [job], count: 1 });
|
||||
}
|
||||
@@ -584,6 +587,7 @@ describe("PlatformApiClient AI providers", () => {
|
||||
await expect(client.listJobs()).resolves.toMatchObject({ count: 1 });
|
||||
await expect(client.listJobs(server.id)).resolves.toMatchObject({ count: 1 });
|
||||
await expect(client.listJobs(undefined, { states: ["queued", "running", "failed"] })).resolves.toMatchObject({ count: 1 });
|
||||
await expect(client.listJobs(undefined, { states: ["queued", "running", "failed"], limit: 25 })).resolves.toMatchObject({ count: 1 });
|
||||
await expect(client.listJobs(server.id, { states: ["queued", "running", "failed"] })).resolves.toMatchObject({ count: 1 });
|
||||
await expect(client.listArtifacts({ ownerKind: "job", ownerId: job.id, state: "available" })).resolves.toMatchObject({ count: 1, items: [{ id: artifact.id }] });
|
||||
await expect(client.openArtifactDownload(artifact.id)).resolves.toMatchObject({ downloadUrl: "/api/v1/artifacts/artifact-1/content", rangeSupported: true });
|
||||
@@ -625,7 +629,7 @@ describe("PlatformApiClient AI providers", () => {
|
||||
client.invokeAI({ requestId: "ai-1", serverInstanceId: server.id, purpose: "config.suggest", prompt: "Tune PVP safely", currentConfig: "server.name=Example Survival #1\n" })
|
||||
).resolves.toMatchObject({ status: "ok", usage: { mocked: true }, configRecommendation: { diffSummary: "review required" } });
|
||||
|
||||
expect(fetchMock).toHaveBeenCalledTimes(46);
|
||||
expect(fetchMock).toHaveBeenCalledTimes(47);
|
||||
});
|
||||
|
||||
it("normalizes server file workspace null arrays from older platform responses", async () => {
|
||||
|
||||
@@ -152,6 +152,7 @@ interface JobListFilter {
|
||||
runEndpointId?: string;
|
||||
state?: JobState;
|
||||
states?: JobState[];
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
export class PlatformApiClient {
|
||||
@@ -925,6 +926,7 @@ function jobListQuery(serverInstanceId: string | undefined, filter: JobListFilte
|
||||
if (filter.runEndpointId) params.set("runEndpointId", filter.runEndpointId);
|
||||
if (filter.state) params.set("state", filter.state);
|
||||
if (filter.states?.length) params.set("states", filter.states.join(","));
|
||||
if (filter.limit !== undefined) params.set("limit", String(filter.limit));
|
||||
const query = params.toString();
|
||||
return query ? `?${query}` : "";
|
||||
}
|
||||
|
||||
@@ -33,6 +33,9 @@ interface OverviewData {
|
||||
jobs: JobResponse[];
|
||||
}
|
||||
|
||||
const overviewJobStates: JobResponse["state"][] = ["failed"];
|
||||
const overviewJobLimit = 50;
|
||||
|
||||
export interface HomePageInitialState {
|
||||
core?: OperationsModuleState<OverviewData>;
|
||||
metrics?: OperationsModuleState<ServerMetricsResponse[]>;
|
||||
@@ -55,7 +58,7 @@ export function HomePage({ session, onNavigate, initialState }: HomePageProps) {
|
||||
try {
|
||||
const [instances, jobs] = await Promise.all([
|
||||
platformApiClient.listServerInstances(),
|
||||
platformApiClient.listJobs()
|
||||
platformApiClient.listJobs(undefined, { states: overviewJobStates, limit: overviewJobLimit })
|
||||
]);
|
||||
setCore({ status: "ready", data: { instances: instances.items, jobs: jobs.items }, refreshedAt: refreshedNow() });
|
||||
} catch (error) {
|
||||
|
||||
@@ -10,6 +10,9 @@ import { cx } from "../utils/classes";
|
||||
|
||||
type ModuleState<T> = { status: "loading" } | { status: "error"; reason: string } | { status: "ready"; data: T };
|
||||
|
||||
const maintenanceJobStates: JobResponse["state"][] = ["failed"];
|
||||
const maintenanceJobLimit = 100;
|
||||
|
||||
export function MaintenancePage({ session, operations, onNavigate }: PageComponentProps) {
|
||||
const [jobs, setJobs] = useState<ModuleState<JobResponse[]>>({ status: "loading" });
|
||||
const [servers, setServers] = useState<ModuleState<ServerInstanceResponse[]>>({ status: "loading" });
|
||||
@@ -18,7 +21,7 @@ export function MaintenancePage({ session, operations, onNavigate }: PageCompone
|
||||
const refreshJobs = useCallback(async () => {
|
||||
setJobs({ status: "loading" });
|
||||
try {
|
||||
const response = await platformApiClient.listJobs();
|
||||
const response = await platformApiClient.listJobs(undefined, { states: maintenanceJobStates, limit: maintenanceJobLimit });
|
||||
setJobs({ status: "ready", data: response.items });
|
||||
} catch (error) {
|
||||
setJobs({ status: "error", reason: error instanceof Error ? error.message : "加载失败" });
|
||||
|
||||
@@ -66,6 +66,7 @@ const serverListRefreshMs = 15000;
|
||||
const serverMetricFreshMs = 30000;
|
||||
const serverForceDeleteConfirmation = "FORCE DELETE";
|
||||
const serverOperationalJobStates: JobResponse["state"][] = ["queued", "accepted", "running", "retrying", "failed"];
|
||||
const serverOperationalJobLimit = 200;
|
||||
|
||||
export function ServersPage({ session, operations, onNavigate }: PageComponentProps) {
|
||||
const [listState, setListState] = useState<ListState>("loading");
|
||||
@@ -97,7 +98,7 @@ export function ServersPage({ session, operations, onNavigate }: PageComponentPr
|
||||
showLoading ? platformApiClient.listGamePlugins() : Promise.resolve(undefined),
|
||||
platformApiClient.listRunEndpoints({ status: "online" }),
|
||||
platformApiClient.listServerInstances(),
|
||||
platformApiClient.listJobs(undefined, { states: serverOperationalJobStates })
|
||||
platformApiClient.listJobs(undefined, { states: serverOperationalJobStates, limit: serverOperationalJobLimit })
|
||||
]);
|
||||
if (pluginResponse) setPlugins(pluginResponse.items);
|
||||
setEndpoints(endpointResponse.items);
|
||||
|
||||
Reference in New Issue
Block a user