Set server command manually for commands with_lock
This commit is contained in:
committed by
Borislav Pantaleev
parent
f7f2b5f447
commit
9fd7290757
@@ -20,7 +20,7 @@ const ServerCommandsPanel = () => {
|
|||||||
const [ isLoading, setLoading ] = useState(true);
|
const [ isLoading, setLoading ] = useState(true);
|
||||||
const [serverCommands, setServerCommands] = useState<{ [key: string]: ServerCommand }>({});
|
const [serverCommands, setServerCommands] = useState<{ [key: string]: ServerCommand }>({});
|
||||||
const [serverProcess, setServerProcess] = useStore<ServerProcessResponse>("serverProcess", { command: "", locked_at: "" });
|
const [serverProcess, setServerProcess] = useStore<ServerProcessResponse>("serverProcess", { command: "", locked_at: "" });
|
||||||
const [commandIsRunning, setCommandIsRunning] = useState<boolean>(false);
|
const [commandIsRunning, setCommandIsRunning] = useState<boolean>(serverProcess.command !== "");
|
||||||
const [commandResult, setCommandResult] = useState<any[]>([]);
|
const [commandResult, setCommandResult] = useState<any[]>([]);
|
||||||
|
|
||||||
const dataProvider = useDataProvider();
|
const dataProvider = useDataProvider();
|
||||||
@@ -56,30 +56,66 @@ const ServerCommandsPanel = () => {
|
|||||||
setCommandResult([]);
|
setCommandResult([]);
|
||||||
setCommandIsRunning(true);
|
setCommandIsRunning(true);
|
||||||
|
|
||||||
const additionalArgs = serverCommands[command].additionalArgs;
|
try {
|
||||||
const response = await dataProvider.runServerCommand(etkeccAdmin, command, { ...(additionalArgs && { args: additionalArgs }) });
|
const additionalArgs = serverCommands[command].additionalArgs || "";
|
||||||
|
const requestParams = additionalArgs ? { args: additionalArgs } : {};
|
||||||
|
|
||||||
if (!response.success) {
|
const response = await dataProvider.runServerCommand(etkeccAdmin, command, requestParams);
|
||||||
return;
|
|
||||||
|
if (!response.success) {
|
||||||
|
setCommandIsRunning(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update UI with success message
|
||||||
|
const commandResults = buildCommandResultMessages(command, additionalArgs);
|
||||||
|
setCommandResult(commandResults);
|
||||||
|
|
||||||
|
// Reset the additional args field
|
||||||
|
resetCommandArgs(command);
|
||||||
|
|
||||||
|
// Update server process status
|
||||||
|
await updateServerProcessStatus(serverCommands[command]);
|
||||||
|
} catch (error) {
|
||||||
|
setCommandIsRunning(false);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const updatedServerCommands = {...serverCommands};
|
const buildCommandResultMessages = (command: string, additionalArgs: string): React.ReactNode[] => {
|
||||||
const commandResult: React.ReactNode[] = [];
|
const results: React.ReactNode[] = [];
|
||||||
|
|
||||||
let commandScheduledText = `Command scheduled: ${command}`;
|
let commandScheduledText = `Command scheduled: ${command}`;
|
||||||
if (serverCommands[command].additionalArgs) {
|
if (additionalArgs) {
|
||||||
commandScheduledText += `, with additional args: ${serverCommands[command].additionalArgs}`;
|
commandScheduledText += `, with additional args: ${additionalArgs}`;
|
||||||
}
|
}
|
||||||
commandResult.push(<Box>{commandScheduledText}</Box>);
|
|
||||||
commandResult.push(<Box>Expect your result in the <Link to={createPath({ resource: "server_notifications", type: "list" })}>Notifications</Link> page soon.</Box>);
|
|
||||||
|
|
||||||
|
results.push(<Box>{commandScheduledText}</Box>);
|
||||||
|
results.push(
|
||||||
|
<Box>
|
||||||
|
Expect your result in the <Link to={createPath({ resource: "server_notifications", type: "list" })}>Notifications</Link> page soon.
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
|
||||||
|
return results;
|
||||||
|
};
|
||||||
|
|
||||||
|
const resetCommandArgs = (command: string) => {
|
||||||
|
const updatedServerCommands = {...serverCommands};
|
||||||
updatedServerCommands[command].additionalArgs = "";
|
updatedServerCommands[command].additionalArgs = "";
|
||||||
setServerCommands(updatedServerCommands);
|
setServerCommands(updatedServerCommands);
|
||||||
|
};
|
||||||
|
|
||||||
setCommandResult(commandResult);
|
const updateServerProcessStatus = async (command: ServerCommand) => {
|
||||||
|
const commandIsLocking = command.with_lock;
|
||||||
|
const serverProcess = await dataProvider.getServerRunningProcess(etkeccAdmin, true);
|
||||||
|
if (!commandIsLocking && serverProcess.command === "") {
|
||||||
|
// if command is not locking, we simulate the "lock" mechanism so notifications will be refetched
|
||||||
|
serverProcess["command"] = command.name;
|
||||||
|
serverProcess["locked_at"] = new Date().toISOString();
|
||||||
|
}
|
||||||
|
|
||||||
const serverProcess: ServerProcessResponse = await dataProvider.getServerRunningProcess(etkeccAdmin, true);
|
|
||||||
setServerProcess({...serverProcess});
|
setServerProcess({...serverProcess});
|
||||||
|
console.log("serverProcess fecht notifications");
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
|
|||||||
@@ -320,6 +320,7 @@ export interface ServerCommand {
|
|||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
args: boolean;
|
args: boolean;
|
||||||
|
with_lock: boolean;
|
||||||
additionalArgs?: string;
|
additionalArgs?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user