@vbarbarosh/node-helpers 3.72.0 → 3.72.2
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 +2 -2
- package/src/cli-apps/watchdog.js +25 -10
- package/src/cli-apps/watchdog.test.js +7 -0
- package/src/shell_spawn.test.js +23 -0
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.2/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.2"} 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.2"} 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.2",
|
|
6
6
|
"description": "A set of helpers for JavaScript/Node.js",
|
|
7
7
|
"unpkg": "dist/browser.js",
|
|
8
8
|
"jsdelivr": "dist/browser.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
],
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "rm -rf dist; webpack",
|
|
19
|
-
"test": "mocha src/**/*.test.js"
|
|
19
|
+
"test": "mocha 'src/**/*.test.js'"
|
|
20
20
|
},
|
|
21
21
|
"keywords": [
|
|
22
22
|
"js",
|
package/src/cli-apps/watchdog.js
CHANGED
|
@@ -9,6 +9,7 @@ const make = require('@vbarbarosh/type-helpers/src/make');
|
|
|
9
9
|
const now_human = require('../now_human');
|
|
10
10
|
const pgid_exists = require('../pgid_exists');
|
|
11
11
|
const pgid_kill_grace = require('../pgid_kill_grace');
|
|
12
|
+
const pkg = require('../../package.json');
|
|
12
13
|
const shell_spawn = require('../shell_spawn');
|
|
13
14
|
|
|
14
15
|
const LOGS_ROOT_UID = cuid.createId();
|
|
@@ -30,7 +31,7 @@ cli(main, report);
|
|
|
30
31
|
|
|
31
32
|
function report(error)
|
|
32
33
|
{
|
|
33
|
-
log(`[
|
|
34
|
+
log(`[watchdog_end_error] ${error.message}`);
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
async function main()
|
|
@@ -41,27 +42,36 @@ async function main()
|
|
|
41
42
|
process.exit(1);
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
|
|
45
|
+
switch (args[0]) {
|
|
46
|
+
case '-v':
|
|
47
|
+
case '--version':
|
|
48
|
+
version();
|
|
49
|
+
process.exit(0);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
log(`[watchdog_begin] v${pkg.version}`);
|
|
45
54
|
|
|
46
55
|
const WATCHDOG_INTERVAL = make(process.env.WATCHDOG_INTERVAL, {type: 'int', min: 1000, default: 5000});
|
|
47
56
|
const heartbeat_server = new HeartbeatServer(WATCHDOG_INTERVAL);
|
|
48
57
|
const WATCHDOG_SOCKET = heartbeat_server.socket_path;
|
|
49
|
-
heartbeat_server.on('heartbeat', () => log('[
|
|
50
|
-
heartbeat_server.on('warning', error => log(`[
|
|
58
|
+
heartbeat_server.on('heartbeat', () => log('[watchdog_ping] ❤️'))
|
|
59
|
+
heartbeat_server.on('warning', error => log(`[watchdog_warn] ⚠️ ${error}`))
|
|
51
60
|
|
|
52
61
|
try {
|
|
53
|
-
log(`[
|
|
62
|
+
log(`[watchdog_interval] ${WATCHDOG_INTERVAL}`);
|
|
63
|
+
log(`[watchdog_socket_path] ${heartbeat_server.socket_path}`);
|
|
54
64
|
const env = {...process.env, WATCHDOG_INTERVAL, WATCHDOG_SOCKET};
|
|
55
65
|
const proc = await shell_spawn(args, {stdio: 'inherit', env, detached: true}).init();
|
|
56
66
|
const pgid = proc.pid; // group id == leader pid
|
|
57
67
|
|
|
58
68
|
const signal = new Promise(function (resolve, reject) {
|
|
59
69
|
process.on('SIGTERM', function () {
|
|
60
|
-
log('[
|
|
70
|
+
log('[watchdog_sigterm]');
|
|
61
71
|
reject(new ExitCodeError(143, 'SIGTERM'));
|
|
62
72
|
});
|
|
63
73
|
process.on('SIGINT', function () {
|
|
64
|
-
log('[
|
|
74
|
+
log('[watchdog_sigint]');
|
|
65
75
|
reject(new ExitCodeError(130, 'SIGINT'));
|
|
66
76
|
});
|
|
67
77
|
});
|
|
@@ -73,17 +83,17 @@ async function main()
|
|
|
73
83
|
finally {
|
|
74
84
|
if (pgid_exists(pgid)) {
|
|
75
85
|
await pgid_kill_grace(pgid, {
|
|
76
|
-
log: s => log(`[
|
|
86
|
+
log: s => log(`[watchdog_pgid_kill_grace] ${s}`),
|
|
77
87
|
});
|
|
78
88
|
}
|
|
79
89
|
}
|
|
80
90
|
}
|
|
81
91
|
finally {
|
|
82
|
-
log('[
|
|
92
|
+
log('[watchdog_dispose] Closing heartbeat server...');
|
|
83
93
|
await Promise.resolve(heartbeat_server.dispose()).timeout(1000);
|
|
84
94
|
}
|
|
85
95
|
|
|
86
|
-
log('[
|
|
96
|
+
log('[watchdog_end_ok]');
|
|
87
97
|
process.exit(0);
|
|
88
98
|
}
|
|
89
99
|
|
|
@@ -144,3 +154,8 @@ watchdog internal error | 1
|
|
|
144
154
|
-----------------------------------
|
|
145
155
|
`.trim() + '\n');
|
|
146
156
|
}
|
|
157
|
+
|
|
158
|
+
function version()
|
|
159
|
+
{
|
|
160
|
+
process.stdout.write(`watchdog v${pkg.version}\n`);
|
|
161
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const Promise = require('bluebird');
|
|
2
|
+
const assert = require('assert');
|
|
3
|
+
const pid_exists = require('./pid_exists');
|
|
4
|
+
const shell_spawn = require('./shell_spawn');
|
|
5
|
+
|
|
6
|
+
describe.skip('shell_spawn', function () {
|
|
7
|
+
describe('Happy Path', function () {
|
|
8
|
+
it('basic', async function () {
|
|
9
|
+
await shell_spawn(['true']).promise().timeout(100);
|
|
10
|
+
});
|
|
11
|
+
it('init + promise', async function () {
|
|
12
|
+
const proc = await shell_spawn(['true']).init();
|
|
13
|
+
await proc.promise().timeout(100);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
it('🏎️ race condition: proc.promise is called after process was terminated', async function () {
|
|
17
|
+
const proc = shell_spawn(['true']);
|
|
18
|
+
assert(pid_exists(proc.pid));
|
|
19
|
+
await Promise.delay(10);
|
|
20
|
+
assert(!pid_exists(proc.pid));
|
|
21
|
+
await proc.promise().timeout(100);
|
|
22
|
+
});
|
|
23
|
+
});
|