aboutsummaryrefslogtreecommitdiff
path: root/src/server/DashSession/Session/agents
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2023-12-04 17:38:36 -0500
committerbobzel <zzzman@gmail.com>2023-12-04 17:38:36 -0500
commit2bd239e39264a362d1fbb013ce2613d03247d78e (patch)
tree6e537dc0c35529c6ee27758a4dec03e23210dbc6 /src/server/DashSession/Session/agents
parentcf7a7dc34426dacf018ac98a83a9589106ae7256 (diff)
trying to do version updates on all npm packages.
Diffstat (limited to 'src/server/DashSession/Session/agents')
-rw-r--r--src/server/DashSession/Session/agents/applied_session_agent.ts9
-rw-r--r--src/server/DashSession/Session/agents/monitor.ts15
-rw-r--r--src/server/DashSession/Session/agents/server_worker.ts4
3 files changed, 19 insertions, 9 deletions
diff --git a/src/server/DashSession/Session/agents/applied_session_agent.ts b/src/server/DashSession/Session/agents/applied_session_agent.ts
index 8339a06dc..2037e93e5 100644
--- a/src/server/DashSession/Session/agents/applied_session_agent.ts
+++ b/src/server/DashSession/Session/agents/applied_session_agent.ts
@@ -1,7 +1,8 @@
-import { isMaster } from "cluster";
+import * as _cluster from "cluster";
import { Monitor } from "./monitor";
import { ServerWorker } from "./server_worker";
-import { Utilities } from "../utilities/utilities";
+const cluster = _cluster as any;
+const isMaster = cluster.isPrimary;
export type ExitHandler = (reason: Error | boolean) => void | Promise<void>;
@@ -15,13 +16,13 @@ export abstract class AppliedSessionAgent {
private launched = false;
public killSession = (reason: string, graceful = true, errorCode = 0) => {
- const target = isMaster ? this.sessionMonitor : this.serverWorker;
+ const target = cluster.default.isPrimary ? this.sessionMonitor : this.serverWorker;
target.killSession(reason, graceful, errorCode);
}
private sessionMonitorRef: Monitor | undefined;
public get sessionMonitor(): Monitor {
- if (!isMaster) {
+ if (!cluster.default.isPrimary) {
this.serverWorker.emit("kill", {
graceful: false,
reason: "Cannot access the session monitor directly from the server worker thread.",
diff --git a/src/server/DashSession/Session/agents/monitor.ts b/src/server/DashSession/Session/agents/monitor.ts
index 9cb5ab576..0f469285e 100644
--- a/src/server/DashSession/Session/agents/monitor.ts
+++ b/src/server/DashSession/Session/agents/monitor.ts
@@ -1,7 +1,8 @@
import { ExitHandler } from "./applied_session_agent";
import { Configuration, configurationSchema, defaultConfig, Identifiers, colorMapping } from "../utilities/session_config";
import Repl, { ReplAction } from "../utilities/repl";
-import { isWorker, setupMaster, on, Worker, fork } from "cluster";
+import * as _cluster from "cluster";
+import { Worker } from "cluster";
import { manage, MessageHandler, ErrorLike } from "./promisified_ipc_manager";
import { red, cyan, white, yellow, blue } from "colors";
import { exec, ExecOptions } from "child_process";
@@ -10,6 +11,11 @@ import { Utilities } from "../utilities/utilities";
import { readFileSync } from "fs";
import IPCMessageReceiver from "./process_message_router";
import { ServerWorker } from "./server_worker";
+const cluster = _cluster as any;
+const isWorker = cluster.isWorker;
+const setupMaster = cluster.setupPrimary;
+const on = cluster.on;
+const fork = cluster.fork;
/**
* Validates and reads the configuration file, accordingly builds a child process factory
@@ -20,7 +26,7 @@ export class Monitor extends IPCMessageReceiver {
private finalized = false;
private exitHandlers: ExitHandler[] = [];
private readonly config: Configuration;
- private activeWorker: Worker | undefined;
+ private activeWorker: Worker| undefined;
private key: string | undefined;
private repl: Repl;
@@ -281,8 +287,11 @@ export class Monitor extends IPCMessageReceiver {
pollingIntervalSeconds: polling.intervalSeconds,
session_key: key
});
- Monitor.IPCManager = manage(this.activeWorker.process, this.handlers);
+ if (this.activeWorker) {
+ Monitor.IPCManager = manage(this.activeWorker.process, this.handlers);
+ }
this.mainLog(cyan(`spawned new server worker with process id ${this.activeWorker?.process.pid}`));
+
}
}
diff --git a/src/server/DashSession/Session/agents/server_worker.ts b/src/server/DashSession/Session/agents/server_worker.ts
index 634b0113d..d8b3ee80b 100644
--- a/src/server/DashSession/Session/agents/server_worker.ts
+++ b/src/server/DashSession/Session/agents/server_worker.ts
@@ -1,4 +1,4 @@
-import { isMaster } from "cluster";
+import cluster from "cluster";
import { green, red, white, yellow } from "colors";
import { get } from "request-promise";
import { ExitHandler } from "./applied_session_agent";
@@ -22,7 +22,7 @@ export class ServerWorker extends IPCMessageReceiver {
private serverPort: number;
private isInitialized = false;
public static Create(work: Function) {
- if (isMaster) {
+ if (cluster.isPrimary) {
console.error(red("cannot create a worker on the monitor process."));
process.exit(1);
} else if (++ServerWorker.count > 1) {