@vbarbarosh/node-helpers 3.72.3 → 3.72.4
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/README.md +1 -1
- package/dist/browser.js +2 -2
- package/package.json +1 -1
- package/src/cli-apps/watchdog.js +15 -6
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ npm install @vbarbarosh/node-helpers
|
|
|
20
20
|
A subset of `@vbarbarosh/node-helpers` is available for browser:
|
|
21
21
|
|
|
22
22
|
```html
|
|
23
|
-
<script src="https://unpkg.com/@vbarbarosh/node-helpers@3.72.
|
|
23
|
+
<script src="https://unpkg.com/@vbarbarosh/node-helpers@3.72.4/dist/browser.js"></script>
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
⚠️ All browser functions are exposed globally.
|
package/dist/browser.js
CHANGED
|
@@ -2499,10 +2499,10 @@ var __webpack_exports__ = {};
|
|
|
2499
2499
|
\******************************/
|
|
2500
2500
|
const ns = new URL(document.currentScript.src).searchParams.get('var') ?? 'h';
|
|
2501
2501
|
if (typeof window[ns] !== 'undefined') {
|
|
2502
|
-
console.log(`❌ @vbarbarosh/node-helpers@${"3.72.
|
|
2502
|
+
console.log(`❌ @vbarbarosh/node-helpers@${"3.72.4"} was not injected — window.${ns} is already in use`);
|
|
2503
2503
|
}
|
|
2504
2504
|
else {
|
|
2505
|
-
console.log(`🎉 @vbarbarosh/node-helpers@${"3.72.
|
|
2505
|
+
console.log(`🎉 @vbarbarosh/node-helpers@${"3.72.4"} successfully exposed as window.${ns}`);
|
|
2506
2506
|
window[ns] = {};
|
|
2507
2507
|
// https://github.com/webpack/webpack/issues/625
|
|
2508
2508
|
// https://webpack.js.org/guides/dependency-management/#require-context
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"author": "Vladimir Barbarosh <vladimir.barbarosh@gmail.com>",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "@vbarbarosh/node-helpers",
|
|
5
|
-
"version": "3.72.
|
|
5
|
+
"version": "3.72.4",
|
|
6
6
|
"description": "A set of helpers for JavaScript/Node.js",
|
|
7
7
|
"unpkg": "dist/browser.js",
|
|
8
8
|
"jsdelivr": "dist/browser.js",
|
package/src/cli-apps/watchdog.js
CHANGED
|
@@ -5,15 +5,19 @@ const HeartbeatServer = require('../HeartbeatServer');
|
|
|
5
5
|
const Promise = require('bluebird');
|
|
6
6
|
const cli = require('../cli');
|
|
7
7
|
const cuid = require('@paralleldrive/cuid2');
|
|
8
|
+
const format_ms3 = require('../format_ms3');
|
|
9
|
+
const format_thousands = require('../format_thousands');
|
|
8
10
|
const make = require('@vbarbarosh/type-helpers/src/make');
|
|
9
|
-
const now_human = require('../now_human');
|
|
10
11
|
const pgid_exists = require('../pgid_exists');
|
|
11
12
|
const pgid_kill_grace = require('../pgid_kill_grace');
|
|
12
13
|
const pkg = require('../../package.json');
|
|
13
14
|
const shell_spawn = require('../shell_spawn');
|
|
14
15
|
|
|
16
|
+
const STARTED_AT = Date.now();
|
|
15
17
|
const LOGS_ROOT_UID = cuid.createId();
|
|
16
18
|
|
|
19
|
+
let PING_COUNTER = 0;
|
|
20
|
+
|
|
17
21
|
// 💎 Only the lack of a valid PING within WATCHDOG_INTERVAL is fatal
|
|
18
22
|
|
|
19
23
|
// Ctrl-C should gracefully terminate a child process and close heartbeat server
|
|
@@ -31,7 +35,7 @@ cli(main, report);
|
|
|
31
35
|
|
|
32
36
|
function report(error)
|
|
33
37
|
{
|
|
34
|
-
log(`[watchdog_end_error] ${error.message}`);
|
|
38
|
+
log(`[watchdog_end_error] ${render_stats()} | ${error.message}`);
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
async function main()
|
|
@@ -55,7 +59,7 @@ async function main()
|
|
|
55
59
|
const WATCHDOG_INTERVAL = make(process.env.WATCHDOG_INTERVAL, {type: 'int', min: 1000, default: 5000});
|
|
56
60
|
const heartbeat_server = new HeartbeatServer(WATCHDOG_INTERVAL);
|
|
57
61
|
const WATCHDOG_SOCKET = heartbeat_server.socket_path;
|
|
58
|
-
heartbeat_server.on('heartbeat', () => log(
|
|
62
|
+
heartbeat_server.on('heartbeat', () => log(`[watchdog_ping] ❤️ ${render_stats(++PING_COUNTER)}`))
|
|
59
63
|
heartbeat_server.on('warning', error => log(`[watchdog_warn] ⚠️ ${error}`))
|
|
60
64
|
|
|
61
65
|
try {
|
|
@@ -94,7 +98,7 @@ async function main()
|
|
|
94
98
|
await Promise.resolve(heartbeat_server.dispose()).timeout(1000);
|
|
95
99
|
}
|
|
96
100
|
|
|
97
|
-
log(
|
|
101
|
+
log(`[watchdog_end_ok] ${render_stats()}`);
|
|
98
102
|
process.exit(0);
|
|
99
103
|
}
|
|
100
104
|
|
|
@@ -102,13 +106,18 @@ function log(s)
|
|
|
102
106
|
{
|
|
103
107
|
const ss = JSON.stringify(s).slice(1, -1).replaceAll('\\"', '"');
|
|
104
108
|
if (ss[0] === '[') {
|
|
105
|
-
console.log(`[${LOGS_ROOT_UID}][
|
|
109
|
+
console.log(`[${LOGS_ROOT_UID}][+${format_ms3(Date.now() - STARTED_AT)}]${ss}`);
|
|
106
110
|
}
|
|
107
111
|
else {
|
|
108
|
-
console.log(`[${LOGS_ROOT_UID}][
|
|
112
|
+
console.log(`[${LOGS_ROOT_UID}][+${format_ms3(Date.now() - STARTED_AT)}] ${ss}`);
|
|
109
113
|
}
|
|
110
114
|
}
|
|
111
115
|
|
|
116
|
+
function render_stats()
|
|
117
|
+
{
|
|
118
|
+
return `pings=${format_thousands(PING_COUNTER)}`;
|
|
119
|
+
}
|
|
120
|
+
|
|
112
121
|
function usage()
|
|
113
122
|
{
|
|
114
123
|
process.stdout.write(`
|