@nxtedition/lib 19.8.21 → 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.
Files changed (2) hide show
  1. package/app.js +18 -22
  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
- let currentLag = 0
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
- ? rxjs.timer(0, 1e3).pipe(
474
- rx.map(() =>
475
- toobusy.lag() > 1e3
476
- ? [
477
- {
478
- id: 'app:toobusy_lag',
479
- level: 40,
480
- code: 'NXT_LAG',
481
- msg: `lag: ${toobusy.lag()}`,
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "19.8.21",
3
+ "version": "19.9.0",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",