generated from samchon/backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.ts
55 lines (48 loc) · 1.93 KB
/
update.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { MutexConnector, RemoteMutex } from "mutex-server";
import { Promisive } from "tgrid/typings/Promisive";
import { UniqueLock } from "tstl/thread/UniqueLock";
import api from "@ORGANIZATION/PROJECT-api";
import { ISystem } from "@ORGANIZATION/PROJECT-api/lib/structures/monitors/ISystem";
import { MyConfiguration } from "../MyConfiguration";
import { MyGlobal } from "../MyGlobal";
import { IUpdateController } from "../updator/internal/IUpdateController";
async function main(): Promise<void> {
// CONFIGURE MODE
if (!process.argv[2])
throw new Error("Error on Updator.update(): no mode specified.");
MyGlobal.setMode(process.argv[2] as typeof MyGlobal.mode);
// CONNECT TO THE UPDATOR SERVER
const connector: MutexConnector<string, null> = new MutexConnector(
MyConfiguration.SYSTEM_PASSWORD(),
null,
);
await connector.connect(
`ws://${MyConfiguration.MASTER_IP()}:${MyConfiguration.UPDATOR_PORT()}/update`,
);
// REQUEST UPDATE WITH MONOPOLYING A GLOBAL MUTEX
const mutex: RemoteMutex = await connector.getMutex("update");
const success: boolean = await UniqueLock.try_lock(mutex, async () => {
const updator: Promisive<IUpdateController> = connector.getDriver();
await updator.update();
});
await connector.close();
// SUCCESS OR NOT
if (success === false) {
console.log("Already on updating.");
process.exit(-1);
}
// PRINT THE COMMIT STATUS
const connection: api.IConnection = {
host: `http://${MyConfiguration.MASTER_IP()}:${MyConfiguration.API_PORT()}`,
};
const system: ISystem = await api.functional.monitors.system.get(
connection,
);
console.log("branch", system.arguments[2], system.commit.branch);
console.log("hash", system.commit.hash);
console.log("commit-time", system.commit.commited_at);
}
main().catch((exp) => {
console.log(exp);
process.exit(-1);
});