aboutsummaryrefslogtreecommitdiff
path: root/src/server/DashSession.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/DashSession.ts')
-rw-r--r--src/server/DashSession.ts89
1 files changed, 44 insertions, 45 deletions
diff --git a/src/server/DashSession.ts b/src/server/DashSession.ts
index 9c36fa17f..c0ebc9687 100644
--- a/src/server/DashSession.ts
+++ b/src/server/DashSession.ts
@@ -3,59 +3,58 @@ import { Email } from "./ActionUtilities";
import { red, yellow } from "colors";
import { SolrManager } from "./ApiManagers/SearchManager";
import { execSync } from "child_process";
-import { isMaster } from "cluster";
import { Utils } from "../Utils";
import { WebSocket } from "./Websocket/Websocket";
import { MessageStore } from "./Message";
import { launchServer } from ".";
-const notificationRecipients = ["samuel_wilkins@brown.edu"];
-const signature = "-Dash Server Session Manager";
+/**
+* If we're the monitor (master) thread, we should launch the monitor logic for the session.
+* Otherwise, we must be on a worker thread that was spawned *by* the monitor (master) thread, and thus
+* our job should be to run the server.
+*/
+export class DashSessionAgent extends Session.AppliedSessionAgent {
-const monitorHooks: Session.MonitorNotifierHooks = {
- key: async (key, masterLog) => {
- const content = `The key for this session (started @ ${new Date().toUTCString()}) is ${key}.\n\n${signature}`;
- const failures = await Email.dispatchAll(notificationRecipients, "Server Termination Key", content);
- if (failures) {
- failures.map(({ recipient, error: { message } }) => masterLog(red(`dispatch failure @ ${recipient} (${yellow(message)})`)));
- return false;
- }
- return true;
- },
- crash: async ({ name, message, stack }, masterLog) => {
- const body = [
- "You, as a Dash Administrator, are being notified of a server crash event. Here's what we know:",
- `name:\n${name}`,
- `message:\n${message}`,
- `stack:\n${stack}`,
- "The server is already restarting itself, but if you're concerned, use the Remote Desktop Connection to monitor progress.",
- ].join("\n\n");
- const content = `${body}\n\n${signature}`;
- const failures = await Email.dispatchAll(notificationRecipients, "Dash Web Server Crash", content);
- if (failures) {
- failures.map(({ recipient, error: { message } }) => masterLog(red(`dispatch failure @ ${recipient} (${yellow(message)})`)));
- return false;
- }
- return true;
- }
-};
+ private readonly notificationRecipients = ["samuel_wilkins@brown.edu"];
+ private readonly signature = "-Dash Server Session Manager";
-export class DashSessionAgent extends Session.AppliedSessionAgent {
+ protected async launchMonitor() {
+ const monitor = await Session.initializeMonitorThread({
+ key: async (key, masterLog) => {
+ const content = `The key for this session (started @ ${new Date().toUTCString()}) is ${key}.\n\n${this.signature}`;
+ const failures = await Email.dispatchAll(this.notificationRecipients, "Server Termination Key", content);
+ if (failures) {
+ failures.map(({ recipient, error: { message } }) => masterLog(red(`dispatch failure @ ${recipient} (${yellow(message)})`)));
+ return false;
+ }
+ return true;
+ },
+ crash: async ({ name, message, stack }, masterLog) => {
+ const body = [
+ "You, as a Dash Administrator, are being notified of a server crash event. Here's what we know:",
+ `name:\n${name}`,
+ `message:\n${message}`,
+ `stack:\n${stack}`,
+ "The server is already restarting itself, but if you're concerned, use the Remote Desktop Connection to monitor progress.",
+ ].join("\n\n");
+ const content = `${body}\n\n${this.signature}`;
+ const failures = await Email.dispatchAll(this.notificationRecipients, "Dash Web Server Crash", content);
+ if (failures) {
+ failures.map(({ recipient, error: { message } }) => masterLog(red(`dispatch failure @ ${recipient} (${yellow(message)})`)));
+ return false;
+ }
+ return true;
+ }
+ });
+ monitor.addReplCommand("pull", [], () => execSync("git pull", { stdio: ["ignore", "inherit", "inherit"] }));
+ monitor.addReplCommand("solr", [/start|stop/g], args => SolrManager.SetRunning(args[0] === "start"));
+ return monitor;
+ }
- /**
- * If we're the monitor (master) thread, we should launch the monitor logic for the session.
- * Otherwise, we must be on a worker thread that was spawned *by* the monitor (master) thread, and thus
- * our job should be to run the server.
- */
- protected async launchImplementation() {
- if (isMaster) {
- this.sessionMonitor = await Session.initializeMonitorThread(monitorHooks);
- this.sessionMonitor.addReplCommand("pull", [], () => execSync("git pull", { stdio: ["ignore", "inherit", "inherit"] }));
- this.sessionMonitor.addReplCommand("solr", [/start|stop/g], args => SolrManager.SetRunning(args[0] === "start"));
- } else {
- this.serverWorker = await Session.initializeWorkerThread(launchServer); // server initialization delegated to worker
- this.serverWorker.addExitHandler(() => Utils.Emit(WebSocket._socket, MessageStore.ConnectionTerminated, "Manual"));
- }
+ protected async launchServerWorker() {
+ const worker = await Session.initializeWorkerThread(launchServer); // server initialization delegated to worker
+ worker.addExitHandler(() => Utils.Emit(WebSocket._socket, MessageStore.ConnectionTerminated, "Manual"));
+ return worker;
}
} \ No newline at end of file