-
Notifications
You must be signed in to change notification settings - Fork 7
/
runner.js
36 lines (31 loc) · 928 Bytes
/
runner.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
import dotenv from 'dotenv';
import {
runConfigInBackground
} from "./src/controllers/runner.js";
import {
initUtils
} from './src/util.js';
dotenv.config();
initUtils();
const payload = JSON.parse(process.env.RUNNER_PAYLOAD);
console.log(`Executing`, payload);
const cleanUpServer = ( /** @type {any} */ code, msg) => {
console.log(`Exiting runner node ${process.pid} with code ${code}`);
if (msg) {
console.log('Additional context: ' + JSON.stringify(msg, Object.getOwnPropertyNames(msg)));
}
};
[`exit`, `SIGINT`, `SIGUSR1`, `SIGUSR2`, `uncaughtException`, `SIGTERM`].forEach((eventType) => {
process.on(eventType, cleanUpServer.bind(null, eventType));
})
// @ts-ignore
const {
body,
domain,
sandbox,
callback
} = payload;
runConfigInBackground(body, domain, sandbox, callback).catch(err => {
console.error(err);
});
console.log(`Starting runner node ${process.pid}`);