diff options
| author | Sam Wilkins <samwilkins333@gmail.com> | 2020-01-11 13:42:06 -0500 |
|---|---|---|
| committer | Sam Wilkins <samwilkins333@gmail.com> | 2020-01-11 13:42:06 -0500 |
| commit | 86f1e0f58940904b8c55284f6787e7422a6665ff (patch) | |
| tree | faeba5e08d5a6fc99aa4f26cd246aca3af3bca5d /src/server/session/agents/server_worker.ts | |
| parent | 120fa84b3e8c794dd882d3613067c5b18ee7ba04 (diff) | |
refactor
Diffstat (limited to 'src/server/session/agents/server_worker.ts')
| -rw-r--r-- | src/server/session/agents/server_worker.ts | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/server/session/agents/server_worker.ts b/src/server/session/agents/server_worker.ts index 50abe398d..23ffb2650 100644 --- a/src/server/session/agents/server_worker.ts +++ b/src/server/session/agents/server_worker.ts @@ -1,7 +1,7 @@ import { ExitHandler } from "./applied_session_agent"; import { isMaster } from "cluster"; -import { PromisifiedIPCManager, Message } from "../utilities/ipc"; -import MessageRouter from "./message_router"; +import { PromisifiedIPCManager, Message, MessageHandler } from "../utilities/ipc"; +import ProcessMessageRouter from "./process_message_router"; import { red, green, white, yellow } from "colors"; import { get } from "request-promise"; import { Monitor } from "./monitor"; @@ -11,8 +11,7 @@ import { Monitor } from "./monitor"; * if its predecessor has died. It itself also polls the server heartbeat, and exits with a notification * email if the server encounters an uncaught exception or if the server cannot be reached. */ -export class ServerWorker extends MessageRouter { - private static IPCManager = new PromisifiedIPCManager(process); +export class ServerWorker extends ProcessMessageRouter { private static count = 0; private shouldServerBeResponsive = false; private exitHandlers: ExitHandler[] = []; @@ -56,10 +55,13 @@ export class ServerWorker extends MessageRouter { * A convenience wrapper to tell the session monitor (parent process) * to carry out the action with the specified message and arguments. */ - public emitToMonitor = (name: string, args?: any, awaitResponse = false) => ServerWorker.IPCManager.emit(name, args, awaitResponse); + public emitToMonitor = (name: string, args?: any) => ServerWorker.IPCManager.emit(name, args); + + public emitToMonitorPromise = (name: string, args?: any) => ServerWorker.IPCManager.emitPromise(name, args); private constructor(work: Function) { super(); + ServerWorker.IPCManager = new PromisifiedIPCManager(process); this.lifecycleNotification(green(`initializing process... ${white(`[${process.execPath} ${process.execArgv.join(" ")}]`)}`)); const { pollingRoute, serverPort, pollingIntervalSeconds, pollingFailureTolerance } = process.env; @@ -80,11 +82,11 @@ export class ServerWorker extends MessageRouter { private configureProcess = () => { ServerWorker.IPCManager.setRouter(this.route); // updates the local values of variables to the those sent from master - this.on("updatePollingInterval", ({ args }: Message<{ newPollingIntervalSeconds: number }>) => { - this.pollingIntervalSeconds = args.newPollingIntervalSeconds; + this.on("updatePollingInterval", ({ newPollingIntervalSeconds }) => { + this.pollingIntervalSeconds = newPollingIntervalSeconds; return new Promise<void>(resolve => setTimeout(resolve, 1000 * 10)); }); - this.on("manualExit", async ({ args: { isSessionEnd } }: Message<{ isSessionEnd: boolean }>) => { + this.on("manualExit", async ({ isSessionEnd }) => { await this.executeExitHandlers(isSessionEnd); process.exit(0); }); |
