forked from projectOpenRAP/OpenRAP
-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.ts
44 lines (40 loc) · 1.5 KB
/
index.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
import { DataBaseSDK } from "./sdks/DataBaseSDK";
import * as fs from "fs";
import * as path from "path";
import * as _ from "lodash";
import { reconciliation as DownloadManagerReconciliation } from "./managers/DownloadManager/DownloadManager";
import NetworkSDK from "./sdks/NetworkSDK";
import { TelemetrySyncManager } from "./managers/TelemetrySyncManager";
// Initialize container
const bootstrap = async () => {
// initialize the telemetry instance, to get it in other modules
// create databases for the container
let dataBase = new DataBaseSDK();
let schema = JSON.parse(
fs.readFileSync(path.join(__dirname, "db", "schemas.json"), {
encoding: "utf8"
})
);
let databases = schema.databases;
for (const db of databases) {
dataBase.createDB(db.name);
}
for (const db of databases) {
if (!_.isEmpty(db["indexes"])) {
for (const index of db.indexes) {
await dataBase.createIndex(db.name, index);
}
}
}
await DownloadManagerReconciliation();
const telemetrySyncManager = new TelemetrySyncManager();
telemetrySyncManager.registerDevice();
let interval =
parseInt(process.env.TELEMETRY_SYNC_INTERVAL_IN_SECS) * 1000 || 30000;
setInterval(() => telemetrySyncManager.batchJob(), interval);
setInterval(() => telemetrySyncManager.syncJob(), interval);
setInterval(() => telemetrySyncManager.cleanUpJob(), interval);
// initialize the network sdk to emit the internet available or disconnected events
new NetworkSDK();
};
export { bootstrap };