@nxtedition/lib 23.0.0 → 23.0.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.
- package/app.js +27 -36
- package/package.json +1 -1
package/app.js
CHANGED
|
@@ -77,26 +77,6 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
77
77
|
logger?.warn({ err }, 'warning')
|
|
78
78
|
})
|
|
79
79
|
|
|
80
|
-
const dailyOffpeakTime = config.dailyOffpeakTime ?? '00:00-04:00'
|
|
81
|
-
|
|
82
|
-
if (dailyOffpeakTime) {
|
|
83
|
-
const [start, end] = dailyOffpeakTime.split('-')
|
|
84
|
-
|
|
85
|
-
let wasOffpeak = null
|
|
86
|
-
|
|
87
|
-
const offPeakInterval = setInterval(() => {
|
|
88
|
-
if (isTimeBetween(new Date(), start, end)) {
|
|
89
|
-
if (!wasOffpeak && global.gc) {
|
|
90
|
-
global.gc()
|
|
91
|
-
}
|
|
92
|
-
wasOffpeak = true
|
|
93
|
-
} else {
|
|
94
|
-
wasOffpeak = false
|
|
95
|
-
}
|
|
96
|
-
}, 60e3)
|
|
97
|
-
destroyers.unshift(() => clearInterval(offPeakInterval))
|
|
98
|
-
}
|
|
99
|
-
|
|
100
80
|
const cleanAppConfig = ({
|
|
101
81
|
status,
|
|
102
82
|
stats,
|
|
@@ -160,6 +140,24 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
160
140
|
} (module:${serviceModule}; instance:${serviceInstanceId}) worker:${serviceWorkerId} Node/${process.version}`) ??
|
|
161
141
|
null)
|
|
162
142
|
|
|
143
|
+
const dailyOffpeakTime = config.dailyOffpeakTime ?? '00:00-04:00'
|
|
144
|
+
|
|
145
|
+
if (dailyOffpeakTime) {
|
|
146
|
+
const [start, end] = dailyOffpeakTime.split('-')
|
|
147
|
+
|
|
148
|
+
let wasOffpeak = null
|
|
149
|
+
setInterval(() => {
|
|
150
|
+
if (isTimeBetween(new Date(), start, end)) {
|
|
151
|
+
if (!wasOffpeak && global.gc) {
|
|
152
|
+
global.gc()
|
|
153
|
+
}
|
|
154
|
+
wasOffpeak = true
|
|
155
|
+
} else {
|
|
156
|
+
wasOffpeak = false
|
|
157
|
+
}
|
|
158
|
+
}, 60e3).unref()
|
|
159
|
+
}
|
|
160
|
+
|
|
163
161
|
{
|
|
164
162
|
const loggerConfig = { ...appConfig.logger, ...config.logger }
|
|
165
163
|
|
|
@@ -290,6 +288,7 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
290
288
|
const lagMap = new LRUCache({ ttl: 10e3, max: 1024 })
|
|
291
289
|
|
|
292
290
|
const lagBC = new BroadcastChannel('nxt:lag')
|
|
291
|
+
lagBC.unref()
|
|
293
292
|
|
|
294
293
|
lagBC.onmessage = ({ data }) => {
|
|
295
294
|
lagMap.set(data.id, data.currentLag)
|
|
@@ -301,7 +300,7 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
301
300
|
}
|
|
302
301
|
})
|
|
303
302
|
|
|
304
|
-
|
|
303
|
+
setInterval(() => {
|
|
305
304
|
let currentLag = Math.max(0, histogram.mean / 1e6 - resolution)
|
|
306
305
|
if (Number.isNaN(currentLag)) {
|
|
307
306
|
currentLag = 0
|
|
@@ -323,12 +322,7 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
323
322
|
appLag = Math.max(appLag, lag ?? 0)
|
|
324
323
|
}
|
|
325
324
|
appLag$.next(appLag)
|
|
326
|
-
}, interval)
|
|
327
|
-
|
|
328
|
-
destroyers.unshift(() => {
|
|
329
|
-
clearInterval(lagInterval)
|
|
330
|
-
lagBC.close()
|
|
331
|
-
})
|
|
325
|
+
}, interval).unref()
|
|
332
326
|
|
|
333
327
|
toobusy = () => currentLag$.value > maxLag
|
|
334
328
|
toobusy.lag = () => currentLag$.value
|
|
@@ -480,6 +474,7 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
480
474
|
}
|
|
481
475
|
|
|
482
476
|
const memoryUsageBC = new BroadcastChannel('nxt:memoryUsage')
|
|
477
|
+
memoryUsageBC.unref()
|
|
483
478
|
|
|
484
479
|
let memoryUsageMap
|
|
485
480
|
if (isMainThread) {
|
|
@@ -489,14 +484,9 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
489
484
|
}
|
|
490
485
|
}
|
|
491
486
|
|
|
492
|
-
|
|
487
|
+
setInterval(() => {
|
|
493
488
|
memoryUsageBC.postMessage({ data: process.memoryUsage(), id: serviceWorkerId })
|
|
494
|
-
}, 1e3)
|
|
495
|
-
|
|
496
|
-
destroyers.unshift(() => {
|
|
497
|
-
clearInterval(memoryUsageInterval)
|
|
498
|
-
memoryUsageBC.close()
|
|
499
|
-
})
|
|
489
|
+
}, 1e3).unref()
|
|
500
490
|
|
|
501
491
|
const startTime = Date.now()
|
|
502
492
|
stats$ = stats$.pipe(
|
|
@@ -833,6 +823,8 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
833
823
|
// TODO (fix): What about cluster?
|
|
834
824
|
|
|
835
825
|
const inspectBC = new BroadcastChannel('nxt:inspect')
|
|
826
|
+
inspectBC.unref()
|
|
827
|
+
|
|
836
828
|
let inspectOpen = false
|
|
837
829
|
|
|
838
830
|
if (!isMainThread) {
|
|
@@ -975,8 +967,7 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
975
967
|
// TODO (fix): What about cluster?
|
|
976
968
|
|
|
977
969
|
const utilsBC = new BroadcastChannel('nxt:utils')
|
|
978
|
-
|
|
979
|
-
destroyers.unshift(() => utilsBC.close())
|
|
970
|
+
utilsBC.unref()
|
|
980
971
|
|
|
981
972
|
utilsBC.onmessage = ({ data }) => {
|
|
982
973
|
const { type } = data
|