From ba1a85c4833820bc228779aa9187315d8b711268 Mon Sep 17 00:00:00 2001 From: Sam Wilkins Date: Sat, 4 Jan 2020 13:18:04 -0800 Subject: added graceful kill option, rename --- src/server/Session/session.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/server/Session') diff --git a/src/server/Session/session.ts b/src/server/Session/session.ts index d1d7aab87..789a40c42 100644 --- a/src/server/Session/session.ts +++ b/src/server/Session/session.ts @@ -30,7 +30,7 @@ export namespace Session { * Validates and reads the configuration file, accordingly builds a child process factory * and spawns off an initial process that will respawn as predecessors die. */ - export async function initializeMaster(): Promise { + export async function initializeMonitorThread(): Promise { let activeWorker: Worker; // read in configuration .json file only once, in the master thread @@ -101,9 +101,13 @@ export namespace Session { setupMaster({ silent: !showServerOutput }); // attempts to kills the active worker ungracefully - const tryKillActiveWorker = (): boolean => { + const tryKillActiveWorker = (strict = true): boolean => { if (activeWorker && !activeWorker.isDead()) { - activeWorker.process.kill(); + if (strict) { + activeWorker.process.kill(); + } else { + activeWorker.kill(); + } return true; } return false; @@ -129,7 +133,7 @@ export namespace Session { switch (message) { case "kill": console.log(masterIdentifier, red("An authorized user has ended the server session from the /kill route")); - tryKillActiveWorker(); + tryKillActiveWorker(false); process.exit(0); case "notify_crash": const { error: { name, message, stack } } = args; @@ -179,7 +183,7 @@ export namespace Session { * email if the server encounters an uncaught exception or if the server cannot be reached. * @param work the function specifying the work to be done by each worker thread */ - export async function initializeWorker(work: Function): Promise { + export async function initializeWorkerThread(work: Function): Promise { let listening = false; // notify master thread (which will log update in the console) of initialization via IPC -- cgit v1.2.3-70-g09d2