@abtnode/util
Advanced tools
Comparing version 1.1.4 to 1.1.5
@@ -10,2 +10,4 @@ module.exports = Object.freeze({ | ||
DEFAULT_DESCRIPTION: 'Web Interface to manage your ABT Node', | ||
NODE_UPGRADE_PROGRESS: Object.freeze({ | ||
@@ -21,2 +23,3 @@ SETUP: 'setup', // backup | ||
NODE_PACKAGE_NAME: '@abtnode/cli', | ||
NODE_COMMAND_NAME: 'abtnode', | ||
@@ -29,2 +32,3 @@ PROCESS_NAME_DAEMON: 'abt-node-daemon', | ||
WEB_WALLET_URL: 'https://web.abtwallet.io', | ||
BLOCKLET_REGISTRY_URL: 'https://blocklet.arcblock.io', | ||
@@ -31,0 +35,0 @@ DEFAULT_DASHBOARD_DOMAIN: '*.ip.abtnet.io', |
@@ -7,3 +7,5 @@ const axios = require('axios'); | ||
const ensureStarted = async (endpoint, timeout = 10 * 1000, elapse = 0) => { | ||
const ONE_SECOND = 1000; | ||
const ensureStarted = async (endpoint, timeout = 10 * ONE_SECOND, elapse = 0) => { | ||
const startTime = Date.now(); | ||
@@ -19,3 +21,3 @@ try { | ||
} | ||
await sleep(1000); | ||
await sleep(ONE_SECOND); | ||
@@ -26,3 +28,3 @@ const spend = elapse + (Date.now() - startTime); | ||
throw new Error( | ||
`the service is not ready within ${Math.ceil(timeout / 1000)} seconds, please check your network` | ||
`the service is not ready within ${Math.ceil(timeout / ONE_SECOND)} seconds, please check your network` | ||
); | ||
@@ -35,4 +37,4 @@ } | ||
const ensureHealthy = async ({ endpoint, minConsecutiveTime = 5 * 1000 }) => { | ||
const checkInterval = 1000; | ||
const ensureHealthy = async ({ endpoint, minConsecutiveTime = 5 * ONE_SECOND }) => { | ||
const checkInterval = ONE_SECOND; | ||
const minCheckTimes = Math.ceil(minConsecutiveTime / checkInterval); | ||
@@ -44,3 +46,3 @@ | ||
try { | ||
const res = await axios({ url: endpoint, method: 'HEAD', timeout: 2000 }); | ||
const res = await axios({ url: endpoint, method: 'HEAD', timeout: 2 * ONE_SECOND }); | ||
debug('ping if healthy response:', { endpoint, status: res.status }); | ||
@@ -58,5 +60,5 @@ } catch (err) { | ||
module.exports = async ({ endpoint, timeout = 10 * 1000, minConsecutiveTime = 5 * 1000 }) => { | ||
module.exports = async ({ endpoint, timeout = 10 * ONE_SECOND, minConsecutiveTime = 5 * ONE_SECOND }) => { | ||
debug('ensure endpoint healthy', { endpoint, minConsecutiveTime }); | ||
if (timeout < 10 * 1000) { | ||
if (timeout < 10 * ONE_SECOND) { | ||
throw new Error('minimum timeout is 10000ms'); | ||
@@ -63,0 +65,0 @@ } |
@@ -31,3 +31,3 @@ const internalIp = require('internal-ip'); | ||
internalIp.v4(), | ||
getExternalIp(timeout), | ||
getExternalIp({ timeout }), | ||
includeV6 ? internalIp.v6() : '', | ||
@@ -34,0 +34,0 @@ includeV6 ? getExternalIp({ v6: true, timeout }) : '', |
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"description": "ArcBlock's JavaScript utility", | ||
@@ -16,5 +16,3 @@ "main": "lib/index.js", | ||
"lint:fix": "eslint --fix tests lib", | ||
"precommit": "CI=1 npm run test", | ||
"prepush": "CI=1 npm run test", | ||
"test": "npm run lint && node tools/jest.js", | ||
"test": "NODE_ENV=test node tools/jest.js", | ||
"coverage": "npm run test -- --coverage" | ||
@@ -49,3 +47,3 @@ }, | ||
}, | ||
"gitHead": "f4c4066cb25eb02511d1de582629e355ecebf740" | ||
"gitHead": "dc76140613615a3bf259109ca5cad684f5963078" | ||
} |
# ArcBlock's JavaScript utility | ||
## Utilities | ||
## Usage | ||
### error handler | ||
For example: | ||
Catch `unhandledRejection` and `unhandledRejection` of the current process, and exit the process with exit code 1. | ||
Usage: | ||
```js | ||
require('@abtnode/util/lib/error-handler'); | ||
``` | ||
### Read blocklet meta | ||
```js | ||
const getBlockletMeta = require('@abtnode/util/lib/parse_blocklet_meta'); | ||
const meta = getBlockletMeta(blockletDir); | ||
``` | ||
### NormalizePathPrefix | ||
### checkDomainMatch | ||
### TryWithTimeout | ||
```js | ||
const { tryWithTimeout } = require('@abtnode/util'); | ||
const tryWithTimeout = require('@abtnode/util/lib/try-with-timeout'); | ||
try { | ||
@@ -31,0 +10,0 @@ await tryWithTimeout(() => new Promise((resolve) => setTimeout(() => resolve(true), 60)), 50); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22529
636
16