forked from samchon/backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.ts
More file actions
36 lines (29 loc) · 1.23 KB
/
Copy pathupdate.ts
File metadata and controls
36 lines (29 loc) · 1.23 KB
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
import { Driver } from "tgrid/components/Driver";
import { MutexConnector, RemoteMutex } from "mutex-server";
import { UniqueLock } from "tstl/thread/UniqueLock";
import { IUpdateController } from "../updator/internal/IUpdateController";
import { Configuration } from "../Configuration";
import { SGlobal } from "../SGlobal";
async function main(): Promise<void>
{
// CONFIGURE MODE
if (process.argv[2])
SGlobal.setMode(process.argv[2].toUpperCase() as typeof SGlobal.mode);
// CONNECT TO THE UPDATOR SERVER
const connector: MutexConnector<string, null> = new MutexConnector(Configuration.SYSTEM_PASSWORD, null);
await connector.connect(`ws://${Configuration.MASTER_IP}:${Configuration.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: Driver.Promisive<IUpdateController> = connector.getDriver();
await updator.update();
});
// SUCCESS OR NOT
if (success === false)
console.log("Already on updating.");
// TEERMINATE
await connector.close();
process.exit(success ? 0 : -1);
}
main();