Skip to content

Commit

Permalink
Merge pull request #401 from bitfinexcom/staging
Browse files Browse the repository at this point in the history
Release version to master
  • Loading branch information
prdn authored Sep 10, 2024
2 parents 1dcc950 + cb55be8 commit 8399316
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bfx-report",
"version": "4.10.7",
"version": "4.10.8",
"description": "Reporting tool",
"main": "worker.js",
"license": "Apache-2.0",
Expand Down
22 changes: 20 additions & 2 deletions workers/loc.api/helpers/api-errors-testers.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const isETimedOutError = (err) => {
}

const isNodeFetchTimeoutError = (err) => {
return /network timeout/i.test(_getErrorString(err))
return /timeout/i.test(_getErrorString(err))
}

const isEAiAgainError = (err) => {
Expand Down Expand Up @@ -79,6 +79,18 @@ const isBadGatewayError = (err) => {
return /Bad Gateway/i.test(_getErrorString(err))
}

const isDNSAvailabilityError = (err) => {
return /ERR_NAME_NOT_RESOLVED/i.test(_getErrorString(err))
}

const isSocketHangUpError = (err) => {
return /socket hang up/i.test(_getErrorString(err))
}

const isCommonNetError = (err) => {
return /net::ERR_/i.test(_getErrorString(err))
}

const isForbiddenError = (err) => {
return /forbidden/i.test(_getErrorString(err))
}
Expand All @@ -101,7 +113,10 @@ const isENetError = (err) => (
isEHostUnreachError(err) ||
isEProtoError(err) ||
isTempUnavailableError(err) ||
isBadGatewayError(err)
isBadGatewayError(err) ||
isDNSAvailabilityError(err) ||
isSocketHangUpError(err) ||
isCommonNetError(err)
)

module.exports = {
Expand All @@ -123,6 +138,9 @@ module.exports = {
isEProtoError,
isTempUnavailableError,
isBadGatewayError,
isDNSAvailabilityError,
isSocketHangUpError,
isCommonNetError,
isENetError,
isForbiddenError,
isMaintenanceError
Expand Down
43 changes: 28 additions & 15 deletions workers/loc.api/helpers/get-data-from-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,26 @@ const {
} = require('./api-errors-testers')

const _delay = (mc = 80000, interrupter) => {
if (_isInterrupted(interrupter)) {
return Promise.resolve({ isInterrupted: true })
}

return new Promise((resolve) => {
const hasInterrupter = interrupter instanceof Interrupter
const timeout = setTimeout(() => {
if (hasInterrupter) {
interrupter.offInterrupt(onceInterruptHandler)
}

resolve()
resolve({ isInterrupted: false })
}, mc)
const onceInterruptHandler = () => {
if (!timeout.hasRef()) {
return
}

clearTimeout(timeout)
resolve()
resolve({ isInterrupted: true })
}

if (hasInterrupter) {
Expand Down Expand Up @@ -116,11 +120,12 @@ module.exports = (
if (countRateLimitError > 100) {
throw err
}
if (_isInterrupted(_interrupter)) {
return { isInterrupted: true }
}

await _delay(ms, _interrupter)
const { isInterrupted } = await _delay(ms, _interrupter)

if (isInterrupted) {
return { isInterrupted }
}

continue
}
Expand All @@ -130,11 +135,12 @@ module.exports = (
if (countNonceSmallError > 20) {
throw err
}
if (_isInterrupted(_interrupter)) {
return { isInterrupted: true }
}

await _delay(1000, _interrupter)
const { isInterrupted } = await _delay(1000, _interrupter)

if (isInterrupted) {
return { isInterrupted }
}

continue
}
Expand All @@ -156,7 +162,13 @@ module.exports = (
await wsEventEmitter.emitENetError(callerName)
}

await _delay(eNetErrorAttemptsTimeoutMs, _interrupter)
const {
isInterrupted
} = await _delay(eNetErrorAttemptsTimeoutMs, _interrupter)

if (isInterrupted) {
return { isInterrupted }
}

continue
}
Expand All @@ -170,11 +182,12 @@ module.exports = (
) {
throw err
}
if (_isInterrupted(_interrupter)) {
return { isInterrupted: true }
}

await _delay(10000, _interrupter)
const { isInterrupted } = await _delay(10000, _interrupter)

if (isInterrupted) {
return { isInterrupted }
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions workers/loc.api/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const {
isEProtoError,
isTempUnavailableError,
isBadGatewayError,
isDNSAvailabilityError,
isSocketHangUpError,
isCommonNetError,
isENetError,
isForbiddenError,
isMaintenanceError
Expand Down Expand Up @@ -93,6 +96,9 @@ module.exports = {
isEProtoError,
isTempUnavailableError,
isBadGatewayError,
isDNSAvailabilityError,
isSocketHangUpError,
isCommonNetError,
isENetError,
isForbiddenError,
isMaintenanceError,
Expand Down

0 comments on commit 8399316

Please sign in to comment.