@naturalcycles/backend-lib 4.10.2 → 4.12.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.
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.deployHealthCheck = exports.deployHealthCheckYargsOptions = void 0;
|
|
4
4
|
const node_util_1 = require("node:util");
|
|
5
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
|
-
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
7
6
|
const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
|
|
8
7
|
const exec_1 = require("@naturalcycles/nodejs-lib/dist/exec");
|
|
9
8
|
const request_log_util_1 = require("../server/request.log.util");
|
|
@@ -66,7 +65,7 @@ async function deployHealthCheck(url, opt = {}) {
|
|
|
66
65
|
let doneReason;
|
|
67
66
|
let failed = false;
|
|
68
67
|
let currentInterval = intervalSec * 1000;
|
|
69
|
-
const
|
|
68
|
+
const fetcher = (0, js_lib_1.getFetcher)();
|
|
70
69
|
while (!done) {
|
|
71
70
|
// eslint-disable-next-line no-await-in-loop
|
|
72
71
|
await makeAttempt();
|
|
@@ -85,18 +84,18 @@ async function deployHealthCheck(url, opt = {}) {
|
|
|
85
84
|
attempt++;
|
|
86
85
|
console.log([`>>`, (0, colors_1.dimGrey)(url), (0, node_util_1.inspect)({ attempt }, inspectOpt)].join(' '));
|
|
87
86
|
const started = Date.now();
|
|
88
|
-
const {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
retry:
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
console.log(err.message);
|
|
96
|
-
return {
|
|
97
|
-
statusCode: 0,
|
|
98
|
-
};
|
|
87
|
+
const { err, fetchResponse } = await fetcher.rawFetch(url, {
|
|
88
|
+
mode: 'json',
|
|
89
|
+
timeoutSeconds: timeoutSec,
|
|
90
|
+
retry: {
|
|
91
|
+
count: 0,
|
|
92
|
+
},
|
|
93
|
+
followRedirects: false,
|
|
99
94
|
});
|
|
95
|
+
if (err) {
|
|
96
|
+
console.log(err);
|
|
97
|
+
}
|
|
98
|
+
const statusCode = fetchResponse?.status || 0;
|
|
100
99
|
if (statusCode === 200) {
|
|
101
100
|
countHealthy++;
|
|
102
101
|
countUnhealthy = 0;
|
|
@@ -5,7 +5,7 @@ const js_lib_1 = require("@naturalcycles/js-lib");
|
|
|
5
5
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
6
6
|
const deployInfo_util_1 = require("./deployInfo.util");
|
|
7
7
|
const { versions } = process;
|
|
8
|
-
const { GAE_APPLICATION, GAE_SERVICE, GAE_VERSION, APP_ENV } = process.env;
|
|
8
|
+
const { GAE_APPLICATION, GAE_SERVICE, GAE_VERSION, APP_ENV, NODE_OPTIONS } = process.env;
|
|
9
9
|
function serverStatusMiddleware(projectDir, extra) {
|
|
10
10
|
return async (req, res) => {
|
|
11
11
|
res.json(getServerStatusData(projectDir, extra));
|
|
@@ -17,7 +17,7 @@ function getServerStatusData(projectDir = process.cwd(), extra) {
|
|
|
17
17
|
const t = (0, js_lib_1.localTime)(ts);
|
|
18
18
|
const deployBuildTime = t.toPretty();
|
|
19
19
|
const buildInfo = [t.toStringCompact(), gitBranch, gitRev].filter(Boolean).join('_');
|
|
20
|
-
return (0, js_lib_1.
|
|
20
|
+
return (0, js_lib_1._filterNullishValues)({
|
|
21
21
|
started: getStartedStr(),
|
|
22
22
|
deployBuildTime,
|
|
23
23
|
APP_ENV,
|
|
@@ -30,6 +30,8 @@ function getServerStatusData(projectDir = process.cwd(), extra) {
|
|
|
30
30
|
cpuAvg: nodejs_lib_1.processSharedUtil.cpuAvg(),
|
|
31
31
|
// resourceUsage: process.resourceUsage?.(),
|
|
32
32
|
versions,
|
|
33
|
+
NODE_OPTIONS,
|
|
34
|
+
fetch: typeof globalThis.fetch === 'function',
|
|
33
35
|
...extra,
|
|
34
36
|
});
|
|
35
37
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { inspect, InspectOptions } from 'node:util'
|
|
2
|
-
import { pDelay, _filterFalsyValues, _ms, _since } from '@naturalcycles/js-lib'
|
|
3
|
-
import { getGot } from '@naturalcycles/nodejs-lib'
|
|
2
|
+
import { pDelay, _filterFalsyValues, _ms, _since, getFetcher } from '@naturalcycles/js-lib'
|
|
4
3
|
import { dimGrey, red } from '@naturalcycles/nodejs-lib/dist/colors'
|
|
5
4
|
import { execCommand } from '@naturalcycles/nodejs-lib/dist/exec'
|
|
6
5
|
import { coloredHttpCode } from '../server/request.log.util'
|
|
@@ -95,7 +94,7 @@ export async function deployHealthCheck(
|
|
|
95
94
|
let failed = false
|
|
96
95
|
let currentInterval = intervalSec * 1000
|
|
97
96
|
|
|
98
|
-
const
|
|
97
|
+
const fetcher = getFetcher()
|
|
99
98
|
|
|
100
99
|
while (!done) {
|
|
101
100
|
// eslint-disable-next-line no-await-in-loop
|
|
@@ -127,20 +126,21 @@ export async function deployHealthCheck(
|
|
|
127
126
|
|
|
128
127
|
const started = Date.now()
|
|
129
128
|
|
|
130
|
-
const {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
retry:
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
console.log(err.message)
|
|
138
|
-
|
|
139
|
-
return {
|
|
140
|
-
statusCode: 0,
|
|
141
|
-
}
|
|
129
|
+
const { err, fetchResponse } = await fetcher.rawFetch(url, {
|
|
130
|
+
mode: 'json',
|
|
131
|
+
timeoutSeconds: timeoutSec,
|
|
132
|
+
retry: {
|
|
133
|
+
count: 0,
|
|
134
|
+
},
|
|
135
|
+
followRedirects: false,
|
|
142
136
|
})
|
|
143
137
|
|
|
138
|
+
if (err) {
|
|
139
|
+
console.log(err)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const statusCode = fetchResponse?.status || 0
|
|
143
|
+
|
|
144
144
|
if (statusCode === 200) {
|
|
145
145
|
countHealthy++
|
|
146
146
|
countUnhealthy = 0
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _filterNullishValues, localTime } from '@naturalcycles/js-lib'
|
|
2
2
|
import { memoryUsageFull, processSharedUtil } from '@naturalcycles/nodejs-lib'
|
|
3
3
|
import { getDeployInfo } from './deployInfo.util'
|
|
4
4
|
import { BackendRequestHandler } from './server.model'
|
|
5
5
|
|
|
6
6
|
const { versions } = process
|
|
7
|
-
const { GAE_APPLICATION, GAE_SERVICE, GAE_VERSION, APP_ENV } = process.env
|
|
7
|
+
const { GAE_APPLICATION, GAE_SERVICE, GAE_VERSION, APP_ENV, NODE_OPTIONS } = process.env
|
|
8
8
|
|
|
9
9
|
export function serverStatusMiddleware(projectDir?: string, extra?: any): BackendRequestHandler {
|
|
10
10
|
return async (req, res) => {
|
|
@@ -21,7 +21,7 @@ export function getServerStatusData(
|
|
|
21
21
|
const deployBuildTime = t.toPretty()
|
|
22
22
|
const buildInfo = [t.toStringCompact(), gitBranch, gitRev].filter(Boolean).join('_')
|
|
23
23
|
|
|
24
|
-
return
|
|
24
|
+
return _filterNullishValues({
|
|
25
25
|
started: getStartedStr(),
|
|
26
26
|
deployBuildTime,
|
|
27
27
|
APP_ENV,
|
|
@@ -34,6 +34,8 @@ export function getServerStatusData(
|
|
|
34
34
|
cpuAvg: processSharedUtil.cpuAvg(),
|
|
35
35
|
// resourceUsage: process.resourceUsage?.(),
|
|
36
36
|
versions,
|
|
37
|
+
NODE_OPTIONS,
|
|
38
|
+
fetch: typeof globalThis.fetch === 'function',
|
|
37
39
|
...extra,
|
|
38
40
|
})
|
|
39
41
|
}
|