@nxtedition/lib 23.6.9 → 23.6.10

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.d.ts CHANGED
@@ -29,6 +29,7 @@ export interface App<Records, RpcMethods, Config = Record<string, unknown>> {
29
29
  logger: Logger
30
30
  trace: unknown // TODO: type
31
31
  toobusy: TooBusy
32
+ underPressure: UnderPressure
32
33
  destroyers: Array<
33
34
  | Subscription
34
35
  | ((logger: Logger) => void)
@@ -58,3 +59,21 @@ export interface TooBusy {
58
59
  appLag$: BehaviorSubject<number>
59
60
  maxLag: number
60
61
  }
62
+
63
+ export interface UnderPressure {
64
+ isUnderPressure: () => boolean
65
+ getPressure: () => Pressure
66
+ pressure$: BehaviorSubject<Pressure>
67
+ [Symbol.dispose]: () => void
68
+ }
69
+
70
+ export interface Pressure {
71
+ eventLoopDelay: number
72
+ maxEventLoopDelay: number
73
+ rssBytes: number
74
+ maxRssBytes: number
75
+ heapUsedBytes: number
76
+ maxHeapUsedBytes: number
77
+ eventLoopUtilized: number
78
+ maxEventLoopUtilization: number
79
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "23.6.9",
3
+ "version": "23.6.10",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
package/under-pressure.js CHANGED
@@ -14,9 +14,7 @@ export default function (opts = {}) {
14
14
  const maxEventLoopDelay = opts.maxEventLoopDelay || 0
15
15
  const maxHeapUsedBytes = opts.maxHeapUsedBytes || 0
16
16
  const maxRssBytes = opts.maxRssBytes || 0
17
- const healthCheck = opts.healthCheck || false
18
17
  const maxEventLoopUtilization = opts.maxEventLoopUtilization || 0
19
- const onPressure = opts.onPressure || (() => {})
20
18
 
21
19
  const checkMaxEventLoopDelay = maxEventLoopDelay > 0
22
20
  const checkMaxHeapUsedBytes = maxHeapUsedBytes > 0
@@ -29,7 +27,6 @@ export default function (opts = {}) {
29
27
  let eventLoopDelay = 0
30
28
  let elu
31
29
  let eventLoopUtilized = 0
32
- let wasUnderPressure = false
33
30
 
34
31
  const histogram = monitorEventLoopDelay({ resolution })
35
32
  histogram.enable()
@@ -42,8 +39,7 @@ export default function (opts = {}) {
42
39
  checkMaxEventLoopUtilization === false &&
43
40
  checkMaxEventLoopDelay === false &&
44
41
  checkMaxHeapUsedBytes === false &&
45
- checkMaxRssBytes === false &&
46
- healthCheck === false
42
+ checkMaxRssBytes === false
47
43
  ) {
48
44
  return
49
45
  }
@@ -70,18 +66,7 @@ export default function (opts = {}) {
70
66
  rssBytes = mem.rss
71
67
  updateEventLoopDelay()
72
68
  updateEventLoopUtilization()
73
-
74
- if (isUnderPressure()) {
75
- if (!wasUnderPressure) {
76
- wasUnderPressure = true
77
- onPressure(getPressure())
78
- pressure$.next(getPressure())
79
- }
80
- } else if (wasUnderPressure) {
81
- wasUnderPressure = false
82
- pressure$.next(null)
83
- }
84
-
69
+ pressure$.next(isUnderPressure() ? getPressure() : null)
85
70
  timer.refresh()
86
71
  }
87
72
 
@@ -118,7 +103,7 @@ export default function (opts = {}) {
118
103
  isUnderPressure,
119
104
  getPressure,
120
105
  get pressure$() {
121
- return pressure$.asObservable()
106
+ return pressure$.asObservable().pipe(rxjs.distinctUntilChanged())
122
107
  },
123
108
  [Symbol.dispose]() {
124
109
  clearTimeout(timer)