@nestjs/observe 0.2.1 → 0.2.2
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.
|
@@ -8,6 +8,16 @@ export declare class ObserveAgentWorker implements OnModuleInit, OnApplicationSh
|
|
|
8
8
|
private readonly nodeRuntimeMetricsService;
|
|
9
9
|
private readonly logger;
|
|
10
10
|
private worker;
|
|
11
|
+
/**
|
|
12
|
+
* Set while `onApplicationShutdown` is tearing the worker down.
|
|
13
|
+
*
|
|
14
|
+
* `Worker#terminate()` stops the thread abruptly, so Node reports exit code
|
|
15
|
+
* 1 - indistinguishable, at the `exit` listener, from a worker that died on
|
|
16
|
+
* its own. Without this flag a graceful shutdown logs an error and spawns a
|
|
17
|
+
* replacement thread that nothing will ever stop, which keeps the event loop
|
|
18
|
+
* alive and can hold the process open.
|
|
19
|
+
*/
|
|
20
|
+
private isTerminating;
|
|
11
21
|
private flushInterval;
|
|
12
22
|
private runtimeMetricsInterval;
|
|
13
23
|
private cpuProfiler;
|
|
@@ -40,6 +40,16 @@ let ObserveAgentWorker = ObserveAgentWorker_1 = class ObserveAgentWorker {
|
|
|
40
40
|
// Null before `initializeWorker` and again after termination, which is what
|
|
41
41
|
// the shutdown path below checks for.
|
|
42
42
|
worker = null;
|
|
43
|
+
/**
|
|
44
|
+
* Set while `onApplicationShutdown` is tearing the worker down.
|
|
45
|
+
*
|
|
46
|
+
* `Worker#terminate()` stops the thread abruptly, so Node reports exit code
|
|
47
|
+
* 1 - indistinguishable, at the `exit` listener, from a worker that died on
|
|
48
|
+
* its own. Without this flag a graceful shutdown logs an error and spawns a
|
|
49
|
+
* replacement thread that nothing will ever stop, which keeps the event loop
|
|
50
|
+
* alive and can hold the process open.
|
|
51
|
+
*/
|
|
52
|
+
isTerminating = false;
|
|
43
53
|
flushInterval;
|
|
44
54
|
runtimeMetricsInterval = null;
|
|
45
55
|
cpuProfiler = null;
|
|
@@ -151,6 +161,7 @@ let ObserveAgentWorker = ObserveAgentWorker_1 = class ObserveAgentWorker {
|
|
|
151
161
|
if (!this.worker) {
|
|
152
162
|
return;
|
|
153
163
|
}
|
|
164
|
+
this.isTerminating = true;
|
|
154
165
|
await this.worker.terminate();
|
|
155
166
|
if (this.options.debug) {
|
|
156
167
|
this.logger.debug("Worker terminated successfully.");
|
|
@@ -213,6 +224,10 @@ let ObserveAgentWorker = ObserveAgentWorker_1 = class ObserveAgentWorker {
|
|
|
213
224
|
this.worker.on("message", (msg) => this.handleMessage(msg));
|
|
214
225
|
this.worker.on("error", (error) => this.handleError(error));
|
|
215
226
|
this.worker.on("exit", (code) => {
|
|
227
|
+
if (this.isTerminating) {
|
|
228
|
+
this.logger.debug("Worker exited on shutdown.");
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
216
231
|
if (code !== 0) {
|
|
217
232
|
this.logger.error(`Worker stopped with exit code ${code}. Restarting worker...`);
|
|
218
233
|
this.initializeWorker(); // Restart the worker
|
package/package.json
CHANGED