@nxtedition/lib 23.6.9 → 23.6.11

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
@@ -16,6 +16,13 @@ export interface AppConfig<Config = Record<string, unknown>> {
16
16
  module?: string
17
17
  version?: string
18
18
  config: Config
19
+ underPressure?: {
20
+ sampleInterval?: number
21
+ maxEventLoopDelay?: number
22
+ maxHeapUsedBytes?: number
23
+ maxRssBytes?: number
24
+ maxEventLoopUtilization?: number
25
+ }
19
26
  [key: string]: unknown
20
27
  }
21
28
 
@@ -29,6 +36,7 @@ export interface App<Records, RpcMethods, Config = Record<string, unknown>> {
29
36
  logger: Logger
30
37
  trace: unknown // TODO: type
31
38
  toobusy: TooBusy
39
+ underPressure: UnderPressure
32
40
  destroyers: Array<
33
41
  | Subscription
34
42
  | ((logger: Logger) => void)
@@ -58,3 +66,21 @@ export interface TooBusy {
58
66
  appLag$: BehaviorSubject<number>
59
67
  maxLag: number
60
68
  }
69
+
70
+ export interface UnderPressure {
71
+ isUnderPressure: () => boolean
72
+ getPressure: () => Pressure
73
+ pressure$: BehaviorSubject<Pressure>
74
+ [Symbol.dispose]: () => void
75
+ }
76
+
77
+ export interface Pressure {
78
+ eventLoopDelay: number
79
+ maxEventLoopDelay: number
80
+ rssBytes: number
81
+ maxRssBytes: number
82
+ heapUsedBytes: number
83
+ maxHeapUsedBytes: number
84
+ eventLoopUtilized: number
85
+ maxEventLoopUtilization: number
86
+ }
package/app.js CHANGED
@@ -641,7 +641,7 @@ export function makeApp(appConfig, onTerminate) {
641
641
  ],
642
642
  ),
643
643
  ) ?? rxjs.of([]),
644
- underPressure.pressure$.pipe(
644
+ underPressure?.pressure$.pipe(
645
645
  rx.map((pressure) =>
646
646
  pressure == null
647
647
  ? []
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "23.6.9",
3
+ "version": "23.6.11",
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)