@nxtedition/lib 19.8.20 → 19.9.0
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 +18 -22
- package/couch.js +1 -2
- package/package.json +1 -1
package/app.js
CHANGED
|
@@ -223,13 +223,13 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
223
223
|
const interval = 500
|
|
224
224
|
const maxLag = 70
|
|
225
225
|
|
|
226
|
-
|
|
226
|
+
const currentLag$ = new rxjs.BehaviorSubject(0)
|
|
227
227
|
|
|
228
228
|
const histogram = monitorEventLoopDelay({ resolution })
|
|
229
229
|
histogram.enable()
|
|
230
230
|
|
|
231
231
|
setInterval(() => {
|
|
232
|
-
currentLag = Math.max(0, histogram.mean / 1e6 - resolution)
|
|
232
|
+
let currentLag = Math.max(0, histogram.mean / 1e6 - resolution)
|
|
233
233
|
if (Number.isNaN(currentLag)) {
|
|
234
234
|
currentLag = null
|
|
235
235
|
}
|
|
@@ -240,10 +240,14 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
240
240
|
} else if (currentLag > maxLag) {
|
|
241
241
|
logger?.warn({ currentLag }, 'lag')
|
|
242
242
|
}
|
|
243
|
+
|
|
244
|
+
currentLag$.next(currentLag)
|
|
243
245
|
}, interval).unref()
|
|
244
246
|
|
|
245
|
-
toobusy = () => currentLag > maxLag
|
|
246
|
-
toobusy.lag = () => currentLag
|
|
247
|
+
toobusy = () => currentLag$.value > maxLag
|
|
248
|
+
toobusy.lag = () => currentLag$.value
|
|
249
|
+
toobusy.lag$ = currentLag$
|
|
250
|
+
toobusy.maxLag = maxLag
|
|
247
251
|
}
|
|
248
252
|
|
|
249
253
|
if (appConfig.couchdb || appConfig.couch) {
|
|
@@ -469,24 +473,16 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
469
473
|
rx.distinctUntilChanged(fp.isEqual),
|
|
470
474
|
rx.repeatWhen((complete$) => complete$.pipe(rx.delay(10e3))),
|
|
471
475
|
),
|
|
472
|
-
toobusy
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
},
|
|
483
|
-
]
|
|
484
|
-
: [],
|
|
485
|
-
),
|
|
486
|
-
rx.startWith([]),
|
|
487
|
-
rx.distinctUntilChanged(fp.isEqual),
|
|
488
|
-
)
|
|
489
|
-
: rxjs.of({}),
|
|
476
|
+
toobusy?.lag$.pipe(
|
|
477
|
+
rx.map((lag) => [
|
|
478
|
+
{
|
|
479
|
+
id: 'app:toobusy_lag',
|
|
480
|
+
level: lag > 1e3 ? 50 : lag > toobusy.maxLAge ? 40 : 30,
|
|
481
|
+
code: 'NXT_LAG',
|
|
482
|
+
msg: `Lag: ${lag.toFixed(2)} ms`,
|
|
483
|
+
},
|
|
484
|
+
]),
|
|
485
|
+
) ?? rxjs.of([]),
|
|
490
486
|
couch
|
|
491
487
|
? rxjs.timer(0, 10e3).pipe(
|
|
492
488
|
rx.exhaustMap(async () => {
|
package/couch.js
CHANGED
|
@@ -488,11 +488,10 @@ export function makeCouch(opts) {
|
|
|
488
488
|
method,
|
|
489
489
|
body: typeof body === 'object' && body ? JSON.stringify(body) : body,
|
|
490
490
|
headers,
|
|
491
|
-
dispatcher: client,
|
|
492
491
|
}
|
|
493
492
|
|
|
494
493
|
return new Promise((resolve, reject) =>
|
|
495
|
-
dispatch(req, {
|
|
494
|
+
dispatch(client, req, {
|
|
496
495
|
resolve,
|
|
497
496
|
reject,
|
|
498
497
|
signal,
|