-
Notifications
You must be signed in to change notification settings - Fork 73
/
launcher.ts
54 lines (48 loc) · 1.49 KB
/
launcher.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
import cluster from "cluster";
import {ConfigurationModule} from "./modules/config";
import {HyperionWorker} from "./workers/hyperionWorker";
import {hLog} from "./helpers/common_functions";
interface WorkerEnv {
worker_role: string;
worker_id: string;
}
const hyperionWorkers = {
ds_pool_worker: 'ds-pool',
reader: 'state-reader',
deserializer: 'deserializer',
continuous_reader: 'state-reader',
repair_reader: 'state-reader',
ingestor: 'indexer',
router: 'ws-router',
delta_updater: 'delta-updater'
};
async function launch() {
const conf = new ConfigurationModule();
const chain_name = conf.config.settings.chain;
const env: WorkerEnv = {
worker_id: process.env.worker_id,
worker_role: process.env.worker_role
};
process.on('SIGINT', function () {
hLog("caught interrupt signal. Exiting now!");
process.exit();
});
if (cluster.isPrimary) {
process.title = `${conf.proc_prefix}-${chain_name}-master`;
const master = await import('./modules/master');
new master.HyperionMaster().runMaster().catch((err) => {
console.log(process.env['worker_role']);
console.log(err);
});
} else {
if (hyperionWorkers[env.worker_role] && !conf.disabledWorkers.has(env.worker_role)) {
process.title = `${conf.proc_prefix}-${chain_name}-${env.worker_role}:${env.worker_id}`;
const mod = (await import(`./workers/${hyperionWorkers[env.worker_role]}`)).default;
const instance = new mod() as HyperionWorker;
await instance.run();
}
}
}
launch().catch((err) => {
console.error(err);
});