-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparrot.js
executable file
·64 lines (54 loc) · 1.42 KB
/
parrot.js
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
56
57
58
59
60
61
62
63
64
#!/usr/bin/env node
"use strict";
const fs = require("fs");
const log = require("./parrot/loglevel");
process.on("uncaughtException", function(error) {
console.critical("Uncaught exception!", error);
process.exit(1);
});
process.on("unhandledRejection", function(error) {
console.critical("Unhandled promise rejection!", error);
process.exit(1);
});
const {Runner} = require("./parrot/main");
async function run(config) {
try {
const runner = new Runner(config);
const reap = async () => {
console.warn("Received HUP");
await runner.close();
};
process.on("SIGHUP", reap);
try {
await runner.run();
}
finally {
process.removeListener("SIGHUP", reap);
}
}
catch (ex) {
console.error("Parrot ded", ex);
}
}
function setupLogging() {
const errfile = fs.createWriteStream("errors.log", { flags: "a" });
const errors = log.patch(new console.Console(errfile), {
colors: false,
level: "error"
});
log.install(console, errors);
}
async function main() {
setupLogging();
let config = JSON.parse(fs.readFileSync(".config.json"));
const {loglevel: ll = "info"} = config;
log.setLevel(ll);
console.debug("set level to", ll);
const {sleep} = require("./parrot/utils");
for (;;) {
config = JSON.parse(fs.readFileSync(".config.json"));
await run(config);
await sleep(10 * 1000);
}
}
main().catch(ex => console.error("Parroting failed", ex));