-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanualStop.ts
35 lines (29 loc) · 1.1 KB
/
manualStop.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { instancesData, serverData } from "../../store";
type OperationReport = {
stoppedInstances?: string[];
message: string;
};
/**
* Stop all instances due to manual turn off, stops the socket and updates server-wide data accordingly.
*/
export const manualStop = (): OperationReport => {
serverData.powerStatus[serverData.powerStatus.length - 1].powerOff = {
instanceId: "<manual>",
timestamp: new Date(),
};
let report: OperationReport = {
message: `All instances stopped successfully.`,
stoppedInstances: [],
};
for (const instanceId of serverData.runningInstances) {
if (instancesData[instanceId].stopTimestamp) continue;
instancesData[instanceId].stopTimestamp = new Date();
instancesData[instanceId].powerOffTimestamp = new Date();
instancesData[instanceId].isManuallyStopped = true;
report.stoppedInstances?.push(instanceId);
}
serverData.runningInstances = serverData.runningInstances.filter(
(instanceId) => !report.stoppedInstances?.includes(instanceId),
);
return report;
};