@bgord/bun 0.29.4 → 0.29.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/graceful-shutdown.service.d.ts +2 -5
- package/dist/graceful-shutdown.service.d.ts.map +1 -1
- package/dist/graceful-shutdown.service.js +18 -21
- package/dist/graceful-shutdown.service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/graceful-shutdown.service.ts +20 -24
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import type { LoggerPort } from "./logger.port";
|
|
2
2
|
type ServerType = ReturnType<typeof Bun.serve>;
|
|
3
|
-
type GracefulShutdownOptions = {
|
|
4
|
-
exitFn?: (code: number) => never;
|
|
5
|
-
};
|
|
6
3
|
export declare class GracefulShutdown {
|
|
7
4
|
private readonly logger;
|
|
8
|
-
private readonly base;
|
|
9
5
|
private readonly exitFn;
|
|
6
|
+
private readonly base;
|
|
10
7
|
private isShuttingDown;
|
|
11
|
-
constructor(logger: LoggerPort,
|
|
8
|
+
constructor(logger: LoggerPort, exitFn?: (code: number) => never);
|
|
12
9
|
private shutdown;
|
|
13
10
|
applyTo(server: ServerType, cleanup?: () => any): void;
|
|
14
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graceful-shutdown.service.d.ts","sourceRoot":"","sources":["../src/graceful-shutdown.service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,KAAK,UAAU,GAAG,UAAU,CAAC,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;AAE/C,
|
|
1
|
+
{"version":3,"file":"graceful-shutdown.service.d.ts","sourceRoot":"","sources":["../src/graceful-shutdown.service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,KAAK,UAAU,GAAG,UAAU,CAAC,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;AAE/C,qBAAa,gBAAgB;IAKzB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IALzB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA0D;IAC/E,OAAO,CAAC,cAAc,CAAS;gBAGZ,MAAM,EAAE,UAAU,EAClB,MAAM,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,KAAuD;IAGpG,OAAO,CAAC,QAAQ;IAqBhB,OAAO,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,GAAE,MAAM,GAAgB;CAqB5D"}
|
|
@@ -2,14 +2,14 @@ import * as tools from "@bgord/tools";
|
|
|
2
2
|
import { formatError } from "./logger-format-error.service";
|
|
3
3
|
export class GracefulShutdown {
|
|
4
4
|
logger;
|
|
5
|
-
base = { operation: "shutdown", component: "infra" };
|
|
6
5
|
exitFn;
|
|
6
|
+
base = { operation: "shutdown", component: "infra" };
|
|
7
7
|
isShuttingDown = false;
|
|
8
|
-
constructor(logger,
|
|
8
|
+
constructor(logger, exitFn = ((code) => process.exit(code))) {
|
|
9
9
|
this.logger = logger;
|
|
10
|
-
this.exitFn =
|
|
10
|
+
this.exitFn = exitFn;
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
shutdown(server, cleanup, exitCode) {
|
|
13
13
|
if (this.isShuttingDown)
|
|
14
14
|
return;
|
|
15
15
|
this.isShuttingDown = true;
|
|
@@ -19,33 +19,30 @@ export class GracefulShutdown {
|
|
|
19
19
|
catch (error) {
|
|
20
20
|
this.logger.error({ message: "Server stop failed", error: formatError(error), ...this.base });
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
this.logger.info({ message: "HTTP server closed", ...this.base })
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this.logger.error({ message: "Cleanup hook failed", error: formatError(error), ...this.base });
|
|
28
|
-
}
|
|
29
|
-
finally {
|
|
22
|
+
Promise.resolve()
|
|
23
|
+
.then(() => cleanup())
|
|
24
|
+
.then(() => this.logger.info({ message: "HTTP server closed", ...this.base }))
|
|
25
|
+
.catch((error) => this.logger.error({ message: "Cleanup hook failed", error: formatError(error), ...this.base }))
|
|
26
|
+
.finally(() => {
|
|
30
27
|
this.exitFn(exitCode);
|
|
31
|
-
}
|
|
28
|
+
});
|
|
32
29
|
}
|
|
33
30
|
applyTo(server, cleanup = tools.noop) {
|
|
34
|
-
process.once("SIGTERM",
|
|
31
|
+
process.once("SIGTERM", () => {
|
|
35
32
|
this.logger.info({ message: "SIGTERM received", ...this.base });
|
|
36
|
-
|
|
33
|
+
this.shutdown(server, cleanup, 0);
|
|
37
34
|
});
|
|
38
|
-
process.once("SIGINT",
|
|
35
|
+
process.once("SIGINT", () => {
|
|
39
36
|
this.logger.info({ message: "SIGINT received", ...this.base });
|
|
40
|
-
|
|
37
|
+
this.shutdown(server, cleanup, 0);
|
|
41
38
|
});
|
|
42
|
-
process.once("unhandledRejection",
|
|
39
|
+
process.once("unhandledRejection", (reason) => {
|
|
43
40
|
this.logger.error({ message: "UnhandledRejection received", error: formatError(reason), ...this.base });
|
|
44
|
-
|
|
41
|
+
this.shutdown(server, cleanup, 1);
|
|
45
42
|
});
|
|
46
|
-
process.once("uncaughtException",
|
|
43
|
+
process.once("uncaughtException", (error) => {
|
|
47
44
|
this.logger.error({ message: "UncaughtException received", error: formatError(error), ...this.base });
|
|
48
|
-
|
|
45
|
+
this.shutdown(server, cleanup, 1);
|
|
49
46
|
});
|
|
50
47
|
}
|
|
51
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graceful-shutdown.service.js","sourceRoot":"","sources":["../src/graceful-shutdown.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"graceful-shutdown.service.js","sourceRoot":"","sources":["../src/graceful-shutdown.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