mirror of
https://github.com/tribufu/node-gamedig
synced 2026-05-06 15:17:36 +00:00
feat: breadth attempt order (#486)
* feat: breadth attempt order * fix: remove stray console log from debugging
This commit is contained in:
parent
6746442254
commit
1ef09d470b
4 changed files with 23 additions and 13 deletions
|
|
@ -8,6 +8,7 @@ const defaultOptions = {
|
|||
maxRetries: 1,
|
||||
stripColors: true,
|
||||
portCache: true,
|
||||
noBreadthOrder: false,
|
||||
ipFamily: 0
|
||||
}
|
||||
|
||||
|
|
@ -76,22 +77,29 @@ export default class QueryRunner {
|
|||
|
||||
const numRetries = userOptions.maxRetries || gameOptions.maxRetries || defaultOptions.maxRetries
|
||||
|
||||
const retries = Array.from({ length: numRetries }, (x, i) => i)
|
||||
|
||||
const attemptOrder = []
|
||||
if (optionsCollection.noBreadthOrder) {
|
||||
attempts.forEach(attempt => retries.forEach(retry => attemptOrder.push({ attempt, retry })))
|
||||
} else {
|
||||
retries.forEach(retry => attempts.forEach(attempt => attemptOrder.push({ attempt, retry })))
|
||||
}
|
||||
|
||||
let attemptNum = 0
|
||||
const errors = []
|
||||
for (const attempt of attempts) {
|
||||
for (let retry = 0; retry < numRetries; retry++) {
|
||||
attemptNum++
|
||||
for (const { attempt, retry } of attemptOrder) {
|
||||
attemptNum++
|
||||
|
||||
try {
|
||||
const response = await this._attempt(attempt)
|
||||
if (attempt.portCache) {
|
||||
this.portCache[`${userOptions.address}:${userOptions.port}`] = attempt.port
|
||||
}
|
||||
return response
|
||||
} catch (e) {
|
||||
e.stack = 'Attempt #' + attemptNum + ' - Port=' + attempt.port + ' Retry=' + (retry) + ':\n' + e.stack
|
||||
errors.push(e)
|
||||
try {
|
||||
const response = await this._attempt(attempt)
|
||||
if (attempt.portCache) {
|
||||
this.portCache[`${userOptions.address}:${userOptions.port}`] = attempt.port
|
||||
}
|
||||
return response
|
||||
} catch (e) {
|
||||
e.stack = 'Attempt #' + attemptNum + ' - Port=' + attempt.port + ' Retry=' + (retry) + ':\n' + e.stack
|
||||
errors.push(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue