-
Notifications
You must be signed in to change notification settings - Fork 1
/
cleanup.ts
35 lines (30 loc) · 938 Bytes
/
cleanup.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 {AppBootContext} from "@nsm/app";
import {setStatus} from "@nsm/server";
import * as bus from "@nsm/event/bus";
import {resolveSequentially} from "@nsm/util/promises";
import {setStopping} from "@nsm/engine/asyncp";
let active = false;
export default function (ctx: AppBootContext, exit?: boolean) {
const { manager, logger, steps } = ctx;
if (active == true) {
return;
}
active = true;
if (exit == true) {
logger.info('SIGINT' + ': Executing stop sequence, please wait');
setStatus("stopping");
setStopping();
}
resolveSequentially(
...(exit == true ? [
// Those steps that should only be called on exit
() => bus.callEvent('nsm:exit', undefined),
() => steps('EXIT', ctx)
] : []),
() => manager.stopRunning()
).then(() => {
if (exit == true) {
process.exit(0);
}
});
}