This repository has been archived by the owner on Apr 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.ts
52 lines (49 loc) · 1.7 KB
/
main.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
import { Params } from './params';
import { debugLog, setLoggerFormat, logger } from './logging';
import { Pool } from './pool';
import { Server } from './server';
import { CacheHTML } from './cache';
const main = async () => {
const params = new Params();
try {
params.parse(process.env);
} catch (error) {
logger.error(error);
process.exit(1);
}
if (params.log === "normal") {
console.log("\n =========================================");
console.log(" =========================================");
console.log(" ============== HTMLSpitter ==============");
console.log(" =========================================");
console.log(" =========================================");
console.log(" == by github.com/qdm12 - Quentin McGaw ==\n");
}
debugLog.main("Starting");
setLoggerFormat(params.log);
logger.info(params.toString());
debugLog.main("Creating pool of browsers");
const pool = new Pool(
params.maxBrowsers,
params.maxPages,
params.maxHits,
params.maxAgeUnused,
params.executablePath,
params.maxQueueSize,
);
debugLog.main("Creating cache");
const cache = new CacheHTML(params.maxCacheSize * 1000000);
debugLog.main("Launching server");
const server = new Server(params.port, pool, cache, params.timeout);
process.on('SIGTERM', () => {
debugLog.main("Closing server");
server.close(
async () => {
debugLog.main("Closing pool of browsers");
await pool.close();
process.exit(0);
}
);
});
}
main();