Hopefully the last small tweaks and fixes to transfer logs

This commit is contained in:
Matthew Penner 2020-12-16 19:30:12 -07:00
parent 8d297a0918
commit 5668a780e2
3 changed files with 14 additions and 10 deletions

View file

@ -67,6 +67,7 @@ export default () => {
const { connected, instance } = ServerContext.useStoreState(state => state.socket); const { connected, instance } = ServerContext.useStoreState(state => state.socket);
const [ canSendCommands ] = usePermissions([ 'control.console' ]); const [ canSendCommands ] = usePermissions([ 'control.console' ]);
const serverId = ServerContext.useStoreState(state => state.server.data!.id); const serverId = ServerContext.useStoreState(state => state.server.data!.id);
const isTransferring = ServerContext.useStoreState(state => state.server.data!.isTransferring)
const [ history, setHistory ] = usePersistedState<string[]>(`${serverId}:command_history`, []); const [ history, setHistory ] = usePersistedState<string[]>(`${serverId}:command_history`, []);
const [ historyIndex, setHistoryIndex ] = useState(-1); const [ historyIndex, setHistoryIndex ] = useState(-1);
@ -165,7 +166,10 @@ export default () => {
useEffect(() => { useEffect(() => {
if (connected && instance) { if (connected && instance) {
// terminal.clear(); // Do not clear the console if the server is being transferred.
if (!isTransferring) {
terminal.clear();
}
instance.addListener('status', handlePowerChangeEvent); instance.addListener('status', handlePowerChangeEvent);
instance.addListener('console output', handleConsoleOutput); instance.addListener('console output', handleConsoleOutput);

View file

@ -6,19 +6,23 @@ const TransferListener = () => {
const getServer = ServerContext.useStoreActions(actions => actions.server.getServer); const getServer = ServerContext.useStoreActions(actions => actions.server.getServer);
const setServerFromState = ServerContext.useStoreActions(actions => actions.server.setServerFromState); const setServerFromState = ServerContext.useStoreActions(actions => actions.server.setServerFromState);
// Listen for the installation completion event and then fire off a request to fetch the updated // Listen for the transfer status event so we can update the state of the server.
// server information. This allows the server to automatically become available to the user if they
// just sit on the page.
useWebsocketEvent('transfer status', (status: string) => { useWebsocketEvent('transfer status', (status: string) => {
if (status === 'starting') { if (status === 'starting') {
setServerFromState(s => ({ ...s, isTransferring: true })); setServerFromState(s => ({ ...s, isTransferring: true }));
return; return;
} }
if (status === 'failure') {
setServerFromState(s => ({ ...s, isTransferring: false }));
return;
}
if (status !== 'success') { if (status !== 'success') {
return; return;
} }
// Refresh the server's information as it's node and allocations were just updated.
getServer(uuid).catch(error => console.error(error)); getServer(uuid).catch(error => console.error(error));
}); });

View file

@ -53,16 +53,12 @@ export default () => {
return; return;
} }
// Force a reconnection to the websocket which will connect us // This code forces a reconnection to the websocket which will connect us to the target node instead of the source node
// to the target node instead of the source node. // in order to be able to receive transfer logs from the target node.
// Close the current websocket connection.
socket.close(); socket.close();
setError('connecting'); setError('connecting');
setConnectionState(false); setConnectionState(false);
setInstance(null); setInstance(null);
connect(uuid); connect(uuid);
}); });