@evanp/activitypub-bot 0.45.8 → 0.45.9
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.
- package/CHANGELOG.md +6 -0
- package/lib/distributionworker.js +25 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -44,13 +44,21 @@ export class DistributionWorker extends Worker {
|
|
|
44
44
|
'Could not deliver activity due to client error'
|
|
45
45
|
)
|
|
46
46
|
if ([408, 425, 429].includes(err.status)) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
if (attempts >= DistributionWorker.#MAX_ATTEMPTS) {
|
|
48
|
+
this._logger.warn(
|
|
49
|
+
{ err, activity: activity.id, inbox, attempts },
|
|
50
|
+
'Could not deliver activity due to client error; no more attempts'
|
|
51
|
+
)
|
|
52
|
+
throw err
|
|
53
|
+
} else {
|
|
54
|
+
this._logger.debug(
|
|
55
|
+
{ err, activity: activity.id, inbox },
|
|
56
|
+
'Retrying on recoverable status'
|
|
57
|
+
)
|
|
58
|
+
const recoverable = new RecoverableError(err.message)
|
|
59
|
+
recoverable.delay = this.#retryDelay(err.headers, attempts)
|
|
60
|
+
throw recoverable
|
|
61
|
+
}
|
|
54
62
|
} else {
|
|
55
63
|
throw err
|
|
56
64
|
}
|
|
@@ -87,6 +95,12 @@ export class DistributionWorker extends Worker {
|
|
|
87
95
|
}
|
|
88
96
|
|
|
89
97
|
#retryDelay (headers, attempts) {
|
|
98
|
+
const headerDelay = this.#headerDelay(headers)
|
|
99
|
+
const attemptsDelay = this.#attemptsDelay(attempts)
|
|
100
|
+
return Math.max(headerDelay, attemptsDelay)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
#headerDelay (headers) {
|
|
90
104
|
if (headers?.['retry-after']) {
|
|
91
105
|
this._logger.debug('using retry-after header')
|
|
92
106
|
const retryAfter = headers['retry-after']
|
|
@@ -96,7 +110,10 @@ export class DistributionWorker extends Worker {
|
|
|
96
110
|
return new Date(retryAfter) - Date.now()
|
|
97
111
|
}
|
|
98
112
|
}
|
|
99
|
-
|
|
113
|
+
return 0
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
#attemptsDelay (attempts) {
|
|
100
117
|
return Math.round((2 ** (attempts - 1) * 1000) * (0.5 + Math.random()))
|
|
101
118
|
}
|
|
102
119
|
}
|