-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathrun.ts
35 lines (31 loc) · 1.1 KB
/
run.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
import config, { sanitized } from './config';
import { start, stop } from '../db';
import version from '../util/version';
import log from '../util/log';
import * as probes from './probes';
import { cancelSystems, cancelExecutors, cancelRuns } from './queries';
async function run () {
log.info({env: config.env}, `${version.full} starting`);
log.debug(sanitized, 'configuration');
const knex = await start(config.db);
log.info('connected to database');
try {
await probes.updateEntities('systems', () => cancelSystems(knex, config.cleaner.timeoutSystems));
await probes.updateEntities('executors', () => cancelExecutors(knex, config.cleaner.timeoutExecutors));
await probes.updateEntities('runs', () => cancelRuns(knex, config.cleaner.timeoutRuns));
} finally {
try {
await probes.pushMetrics();
log.info('metrics sent');
} finally {
await stop();
}
}
}
if (require.main === module) {
process.on('unhandledRejection', (reason: any) => {
log.fatal(reason);
throw reason;
});
run();
}