feat(core): request daemon shutdown (#13034)

Co-authored-by: Victor Savkin <vsavkin@users.noreply.github.com>
This commit is contained in:
Jonathan Cammisuli 2022-11-07 13:34:56 -05:00 committed by GitHub
parent a623e5290e
commit 4ae9ee5506
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 0 deletions

View File

@ -93,6 +93,10 @@ export class DaemonClient {
this._connected = false;
}
async requestShutdown(): Promise<void> {
return this.sendToDaemonViaQueue({ type: 'REQUEST_SHUTDOWN' });
}
async getProjectGraph(): Promise<ProjectGraph> {
return (await this.sendToDaemonViaQueue({ type: 'REQUEST_PROJECT_GRAPH' }))
.projectGraph;

View File

@ -0,0 +1,26 @@
import { Server } from 'net';
import { handleServerProcessTermination } from './shutdown-utils';
export async function handleRequestShutdown(
server: Server,
numberOfConnections: number
) {
// 1 connection is the client asking to shut down
if (numberOfConnections > 1) {
return {
description: `Unable to shutdown the daemon. ${numberOfConnections} connections are open.`,
response: '{}',
};
} else {
setTimeout(async () => {
await handleServerProcessTermination({
server,
reason: 'Request to shutdown',
});
}, 0);
return {
description: 'Shutdown initiated',
response: '{}',
};
}
}

View File

@ -40,6 +40,7 @@ import {
disableOutputsTracking,
processFileChangesInOutputs,
} from './outputs-tracking';
import { handleRequestShutdown } from './handle-request-shutdown';
let performanceObserver: PerformanceObserver | undefined;
let workspaceWatcherError: Error | undefined;
@ -130,6 +131,11 @@ async function handleMessage(socket, data: string) {
await handleResult(socket, await handleRecordOutputsHash(payload));
} else if (payload.type === 'OUTPUTS_HASHES_MATCH') {
await handleResult(socket, await handleOutputsHashesMatch(payload));
} else if (payload.type === 'REQUEST_SHUTDOWN') {
await handleResult(
socket,
await handleRequestShutdown(server, numberOfOpenConnections)
);
} else {
await respondWithErrorAndExit(
socket,