merge dev

This commit is contained in:
Olivier Gagnon
2021-10-07 17:58:32 -04:00
59 changed files with 617 additions and 671 deletions

View File

@@ -11,7 +11,7 @@ import { RamCostConstants } from "./RamCostGenerator";
import { RunningScript } from "../Script/RunningScript";
import { Script } from "../Script/Script";
import { AllServers } from "../Server/AllServers";
import { GetServer } from "../Server/AllServers";
import { BaseServer } from "../Server/BaseServer";
import { IMap } from "../types";
@@ -104,11 +104,11 @@ export class WorkerScript {
/**
* IP Address on which this script is running
*/
serverIp: string;
hostname: string;
constructor(runningScriptObj: RunningScript, pid: number, nsFuncsGenerator?: (ws: WorkerScript) => any) {
this.name = runningScriptObj.filename;
this.serverIp = runningScriptObj.server;
this.hostname = runningScriptObj.server;
const sanitizedPid = Math.round(pid);
if (typeof sanitizedPid !== "number" || isNaN(sanitizedPid)) {
@@ -118,9 +118,9 @@ export class WorkerScript {
runningScriptObj.pid = sanitizedPid;
// Get the underlying script's code
const server = AllServers[this.serverIp];
const server = GetServer(this.hostname);
if (server == null) {
throw new Error(`WorkerScript constructed with invalid server ip: ${this.serverIp}`);
throw new Error(`WorkerScript constructed with invalid server ip: ${this.hostname}`);
}
let found = false;
for (let i = 0; i < server.scripts.length; ++i) {
@@ -147,7 +147,7 @@ export class WorkerScript {
* Returns the Server on which this script is running
*/
getServer(): BaseServer {
const server = AllServers[this.serverIp];
const server = GetServer(this.hostname);
if (server == null) throw new Error(`Script ${this.name} pid ${this.pid} is running on non-existent server?`);
return server;
}

View File

@@ -7,17 +7,17 @@ import { workerScripts } from "./WorkerScripts";
import { WorkerScriptStartStopEventEmitter } from "./WorkerScriptStartStopEventEmitter";
import { RunningScript } from "../Script/RunningScript";
import { AllServers } from "../Server/AllServers";
import { GetServer } from "../Server/AllServers";
import { compareArrays } from "../utils/helpers/compareArrays";
import { roundToTwo } from "../utils/helpers/roundToTwo";
export function killWorkerScript(runningScriptObj: RunningScript, serverIp: string, rerenderUi?: boolean): boolean;
export function killWorkerScript(runningScriptObj: RunningScript, hostname: string, rerenderUi?: boolean): boolean;
export function killWorkerScript(workerScript: WorkerScript): boolean;
export function killWorkerScript(pid: number): boolean;
export function killWorkerScript(
script: RunningScript | WorkerScript | number,
serverIp?: string,
hostname?: string,
rerenderUi?: boolean,
): boolean {
if (rerenderUi == null || typeof rerenderUi !== "boolean") {
@@ -28,7 +28,7 @@ export function killWorkerScript(
stopAndCleanUpWorkerScript(script);
return true;
} else if (script instanceof RunningScript && typeof serverIp === "string") {
} else if (script instanceof RunningScript && typeof hostname === "string") {
// Try to kill by PID
const res = killWorkerScriptByPid(script.pid, rerenderUi);
if (res) {
@@ -37,7 +37,7 @@ export function killWorkerScript(
// If for some reason that doesn't work, we'll try the old way
for (const ws of workerScripts.values()) {
if (ws.name == script.filename && ws.serverIp == serverIp && compareArrays(ws.args, script.args)) {
if (ws.name == script.filename && ws.hostname == hostname && compareArrays(ws.args, script.args)) {
stopAndCleanUpWorkerScript(ws, rerenderUi);
return true;
@@ -80,11 +80,11 @@ function stopAndCleanUpWorkerScript(workerScript: WorkerScript, rerenderUi = tru
*/
function removeWorkerScript(workerScript: WorkerScript, rerenderUi = true): void {
if (workerScript instanceof WorkerScript) {
const ip = workerScript.serverIp;
const ip = workerScript.hostname;
const name = workerScript.name;
// Get the server on which the script runs
const server = AllServers[ip];
const server = GetServer(ip);
if (server == null) {
console.error(`Could not find server on which this script is running: ${ip}`);
return;