feat(core): request daemon shutdown (#13034)
Co-authored-by: Victor Savkin <vsavkin@users.noreply.github.com>
This commit is contained in:
parent
a623e5290e
commit
4ae9ee5506
@ -93,6 +93,10 @@ export class DaemonClient {
|
|||||||
this._connected = false;
|
this._connected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async requestShutdown(): Promise<void> {
|
||||||
|
return this.sendToDaemonViaQueue({ type: 'REQUEST_SHUTDOWN' });
|
||||||
|
}
|
||||||
|
|
||||||
async getProjectGraph(): Promise<ProjectGraph> {
|
async getProjectGraph(): Promise<ProjectGraph> {
|
||||||
return (await this.sendToDaemonViaQueue({ type: 'REQUEST_PROJECT_GRAPH' }))
|
return (await this.sendToDaemonViaQueue({ type: 'REQUEST_PROJECT_GRAPH' }))
|
||||||
.projectGraph;
|
.projectGraph;
|
||||||
|
|||||||
26
packages/nx/src/daemon/server/handle-request-shutdown.ts
Normal file
26
packages/nx/src/daemon/server/handle-request-shutdown.ts
Normal 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: '{}',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -40,6 +40,7 @@ import {
|
|||||||
disableOutputsTracking,
|
disableOutputsTracking,
|
||||||
processFileChangesInOutputs,
|
processFileChangesInOutputs,
|
||||||
} from './outputs-tracking';
|
} from './outputs-tracking';
|
||||||
|
import { handleRequestShutdown } from './handle-request-shutdown';
|
||||||
|
|
||||||
let performanceObserver: PerformanceObserver | undefined;
|
let performanceObserver: PerformanceObserver | undefined;
|
||||||
let workspaceWatcherError: Error | undefined;
|
let workspaceWatcherError: Error | undefined;
|
||||||
@ -130,6 +131,11 @@ async function handleMessage(socket, data: string) {
|
|||||||
await handleResult(socket, await handleRecordOutputsHash(payload));
|
await handleResult(socket, await handleRecordOutputsHash(payload));
|
||||||
} else if (payload.type === 'OUTPUTS_HASHES_MATCH') {
|
} else if (payload.type === 'OUTPUTS_HASHES_MATCH') {
|
||||||
await handleResult(socket, await handleOutputsHashesMatch(payload));
|
await handleResult(socket, await handleOutputsHashesMatch(payload));
|
||||||
|
} else if (payload.type === 'REQUEST_SHUTDOWN') {
|
||||||
|
await handleResult(
|
||||||
|
socket,
|
||||||
|
await handleRequestShutdown(server, numberOfOpenConnections)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
await respondWithErrorAndExit(
|
await respondWithErrorAndExit(
|
||||||
socket,
|
socket,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user