@naturalcycles/backend-lib 4.10.2 → 4.11.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 got = (0, nodejs_lib_1.getGot)();
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 { statusCode } = await got(url, {
89
- responseType: 'json',
90
- timeout: timeoutSec * 1000,
91
- retry: 0,
92
- followRedirect: false,
93
- throwHttpErrors: false,
94
- }).catch((err) => {
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/backend-lib",
3
- "version": "4.10.2",
3
+ "version": "4.11.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install && patch-package",
6
6
  "serve": "APP_ENV=dev nodemon",
@@ -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 got = getGot()
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 { statusCode } = await got(url, {
131
- responseType: 'json',
132
- timeout: timeoutSec * 1000,
133
- retry: 0, // no retries allowed
134
- followRedirect: false,
135
- throwHttpErrors: false,
136
- }).catch((err: Error) => {
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