Add queue stats for V2V

This commit is contained in:
Brandon Thomas committed 2023-07-24 02:48:01 -04:00
1 parent 725450adcf
commit 4705d6bed8
3 files changed
+81 -15

No files matched your search

+4
View File
@@ -97,6 +97,10 @@ class ApiConfig {
return `${this.getApiOrigin()}/session`;
}
getQueueStats(): string {
return `${this.getApiOrigin()}/v1/stats/queues`;
}
listTts(): string {
return `${this.getApiOrigin()}/tts/list`;
}
@@ -0,0 +1,55 @@
import { ApiConfig } from "../../ApiConfig";
export interface GetQueueStatsSuccessResponse {
success: boolean,
cache_time: Date,
refresh_interval_millis: number,
inference: InferenceInfo,
legacy_tts: LegacyTtsInfo,
}
export interface InferenceInfo {
pending_job_count: number,
}
export interface LegacyTtsInfo {
pending_job_count: number,
}
export interface GetQueueStatsErrorResponse {
}
export type GetQueueStatsResponse = GetQueueStatsSuccessResponse | GetQueueStatsErrorResponse;
export function GetQueueStatsIsOk(response: GetQueueStatsResponse): response is GetQueueStatsSuccessResponse {
return response.hasOwnProperty('cache_time');
}
export function GetQueueStatsIsErr(response: GetQueueStatsResponse): response is GetQueueStatsErrorResponse {
return !response.hasOwnProperty('cache_time');
}
export async function GetQueueStats() : Promise<GetQueueStatsResponse> {
const endpoint = new ApiConfig().getQueueStats();
return fetch(endpoint, {
method: 'GET',
credentials: 'include',
headers: {
'Accept': 'application/json',
},
})
.then(res => res.json())
.then(res => {
if (res && 'success' in res && res['success']) {
// NB: Timestamps aren't converted to Date objects on their own!
res['cache_time'] = new Date(res['cache_time']);
return res;
} else {
return { success : false };
}
})
.catch(e => {
return { success : false };
});
}
@@ -18,10 +18,10 @@ import {
GetServerInfoSuccessResponse,
} from "@storyteller/components/src/api/server/GetServerInfo";
import {
GetPendingTtsJobCount,
GetPendingTtsJobCountIsOk,
GetPendingTtsJobCountSuccessResponse,
} from "@storyteller/components/src/api/tts/GetPendingTtsJobCount";
GetQueueStats,
GetQueueStatsIsOk,
GetQueueStatsSuccessResponse,
} from "@storyteller/components/src/api/stats/queues/GetQueueStats";
const DEFAULT_QUEUE_REFRESH_INTERVAL_MILLIS = 15000;
@@ -45,22 +45,27 @@ function FooterNav(props: Props) {
getServerInfo();
}, [getServerInfo]);
const [pendingTtsJobs, setPendingTtsJobs] =
useState<GetPendingTtsJobCountSuccessResponse>({
const [queueStats, setQueueStats] =
useState<GetQueueStatsSuccessResponse>({
success: true,
pending_job_count: 0,
cache_time: new Date(0), // NB: Epoch is used for vector clock's initial state
refresh_interval_millis: DEFAULT_QUEUE_REFRESH_INTERVAL_MILLIS,
inference: {
pending_job_count: 0,
},
legacy_tts: {
pending_job_count: 0,
},
});
useEffect(() => {
const fetch = async () => {
const response = await GetPendingTtsJobCount();
if (GetPendingTtsJobCountIsOk(response)) {
const response = await GetQueueStats();
if (GetQueueStatsIsOk(response)) {
if (
response.cache_time.getTime() > pendingTtsJobs.cache_time.getTime()
response.cache_time.getTime() > queueStats.cache_time.getTime()
) {
setPendingTtsJobs(response);
setQueueStats(response);
}
}
};
@@ -68,13 +73,12 @@ function FooterNav(props: Props) {
//const interval = setInterval(async () => fetch(), 15000);
const refreshInterval = Math.max(
DEFAULT_QUEUE_REFRESH_INTERVAL_MILLIS,
pendingTtsJobs.refresh_interval_millis
queueStats.refresh_interval_millis
);
console.log("new interval", refreshInterval);
const interval = setInterval(async () => fetch(), refreshInterval);
fetch();
return () => clearInterval(interval);
}, [pendingTtsJobs]);
}, [queueStats]);
let myDataLink = WebUrl.signupPage();
@@ -118,7 +122,10 @@ function FooterNav(props: Props) {
<div className="footer-bar text-center text-lg-start">
<div className="container fw-medium">
TTS Queued:{" "}
<span className="text-red">{pendingTtsJobs.pending_job_count}</span>
<span className="text-red">{queueStats.legacy_tts.pending_job_count}</span>
{" "}
V2V Queued:{" "}
<span className="text-red">{queueStats.inference.pending_job_count}</span>
</div>
</div>
<div className="container py-5">