burst cache for status, lock, notifications if command is running

This commit is contained in:
Borislav Pantaleev 2025-02-27 00:06:01 +02:00
parent 201da84967
commit ee7aa12fd0
4 changed files with 28 additions and 11 deletions

View File

@ -31,7 +31,6 @@ const ServerCommandsPanel = () => {
if (serverCommandsResponse) {
const serverCommands = serverCommandsResponse;
Object.keys(serverCommandsResponse).forEach((command: string) => {
// serverCommands[command] = serverCommandsResponse[command];
serverCommands[command].additionalArgs = "";
});
setServerCommands(serverCommands);
@ -41,6 +40,12 @@ const ServerCommandsPanel = () => {
fetchIsAdmin();
}, []);
useEffect(() => {
if (serverProcess.command === "") {
setCommandIsRunning(false);
}
}, [serverProcess]);
const setCommandAdditionalArgs = (command: string, additionalArgs: string) => {
const updatedServerCommands = {...serverCommands};
updatedServerCommands[command].additionalArgs = additionalArgs;
@ -53,7 +58,6 @@ const ServerCommandsPanel = () => {
const response = await dataProvider.runServerCommand(etkeccAdmin, command);
setCommandIsRunning(false);
if (!response.success) {
return;
}
@ -108,6 +112,7 @@ const ServerCommandsPanel = () => {
<TableCell>
{args && <TextField
size="small"
variant="standard"
onChange={(e) => {
setCommandAdditionalArgs(command, e.target.value);
}}

View File

@ -21,7 +21,7 @@ const useServerNotifications = () => {
const { notifications, success } = serverNotifications;
const fetchNotifications = async () => {
const notificationsResponse: ServerNotificationsResponse = await dataProvider.getServerNotifications(etkeccAdmin);
const notificationsResponse: ServerNotificationsResponse = await dataProvider.getServerNotifications(etkeccAdmin, command !== "");
setServerNotifications({
...notificationsResponse,
notifications: notificationsResponse.notifications,

View File

@ -52,13 +52,15 @@ const SERVER_CURRENT_PROCCESS_INTERVAL_TIME = 5 * 1000;
const useServerStatus = () => {
const [serverStatus, setServerStatus] = useStore<ServerStatusResponse>("serverStatus", { ok: false, success: false, host: "", results: [] });
const [serverProcess, setServerProcess] = useStore<ServerProcessResponse>("serverProcess", { command: "", locked_at: "" });
const { command, locked_at } = serverProcess;
const { etkeccAdmin } = useAppContext();
const dataProvider = useDataProvider();
const isOkay = serverStatus.ok;
const successCheck = serverStatus.success;
const checkServerStatus = async () => {
const serverStatus: ServerStatusResponse = await dataProvider.getServerStatus(etkeccAdmin);
const serverStatus: ServerStatusResponse = await dataProvider.getServerStatus(etkeccAdmin, command !== "");
setServerStatus({
ok: serverStatus.ok,
success: serverStatus.success,
@ -89,7 +91,7 @@ const useServerStatus = () => {
clearInterval(serverStatusInterval);
}
}
}, [etkeccAdmin]);
}, [etkeccAdmin, command]);
return { isOkay, successCheck };
};
@ -101,7 +103,7 @@ const useCurrentServerProcess = () => {
const { command, locked_at } = serverProcess;
const checkServerRunningProcess = async () => {
const serverProcess: ServerProcessResponse = await dataProvider.getServerRunningProcess(etkeccAdmin);
const serverProcess: ServerProcessResponse = await dataProvider.getServerRunningProcess(etkeccAdmin, command !== "");
setServerProcess({
...serverProcess,
command: serverProcess.command,
@ -130,7 +132,7 @@ const useCurrentServerProcess = () => {
clearInterval(serverCheckInterval);
}
}
}, [etkeccAdmin]);
}, [etkeccAdmin, command]);
return { command, locked_at };
};

View File

@ -1042,9 +1042,14 @@ const baseDataProvider: SynapseDataProvider = {
return { locked_at, command };
},
getServerStatus: async (etkeAdminUrl: string): Promise<ServerStatusResponse> => {
getServerStatus: async (etkeAdminUrl: string, burstCache: boolean = false): Promise<ServerStatusResponse> => {
let serverURL = `${etkeAdminUrl}/status`;
if (burstCache) {
serverURL += `?time=${new Date().getTime()}`;
}
try {
const response = await fetch(`${etkeAdminUrl}/status`, {
const response = await fetch(serverURL, {
headers: {
"Authorization": `Bearer ${localStorage.getItem("access_token")}`
}
@ -1066,9 +1071,14 @@ const baseDataProvider: SynapseDataProvider = {
return { success: false, ok: false, host: "", results: [] };
},
getServerNotifications: async (serverNotificationsUrl: string): Promise<ServerNotificationsResponse> => {
getServerNotifications: async (serverNotificationsUrl: string, burstCache: boolean = false): Promise<ServerNotificationsResponse> => {
let serverURL = `${serverNotificationsUrl}/notifications`;
if (burstCache) {
serverURL += `?time=${new Date().getTime()}`;
}
try {
const response = await fetch(`${serverNotificationsUrl}/notifications`, {
const response = await fetch(serverURL, {
headers: {
"Authorization": `Bearer ${localStorage.getItem("access_token")}`
}