@evanp/activitypub-bot 0.32.2 → 0.32.3
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/lib/distributionworker.js +26 -18
- package/package.json +1 -1
|
@@ -58,37 +58,31 @@ export class DistributionWorker {
|
|
|
58
58
|
{ error, activity: activity.id, inbox },
|
|
59
59
|
'Could not deliver activity due to client error'
|
|
60
60
|
)
|
|
61
|
-
if (error.status
|
|
61
|
+
if ([408, 425, 429].includes(error.status)) {
|
|
62
62
|
this.#logger.debug(
|
|
63
63
|
{ error, activity: activity.id, inbox },
|
|
64
|
-
'Retrying on
|
|
64
|
+
'Retrying on recoverable status'
|
|
65
65
|
)
|
|
66
|
-
|
|
67
|
-
if (error.headers && error.headers['retry-after']) {
|
|
68
|
-
this.#logger.debug('using retry-after header')
|
|
69
|
-
const retryAfter = error.headers['retry-after']
|
|
70
|
-
if (/^\d+$/.test(retryAfter)) {
|
|
71
|
-
delay = parseInt(retryAfter, 10) * 1000
|
|
72
|
-
} else {
|
|
73
|
-
delay = new Date(retryAfter) - Date.now()
|
|
74
|
-
}
|
|
75
|
-
} else {
|
|
76
|
-
this.#logger.debug('exponential backoff')
|
|
77
|
-
delay = Math.round((2 ** (attempts - 1) * 1000) * (0.5 + Math.random()))
|
|
78
|
-
}
|
|
66
|
+
const delay = this.#retryDelay(error.headers, attempts)
|
|
79
67
|
await this.#jobQueue.retryAfter(jobId, this.#workerId, delay)
|
|
80
68
|
} else {
|
|
81
69
|
await this.#jobQueue.fail(jobId, this.#workerId)
|
|
82
70
|
}
|
|
83
71
|
} else if (error.status >= 500 && error.status < 600) {
|
|
84
|
-
if (
|
|
72
|
+
if ([501, 505, 508, 510].includes(error.status)) {
|
|
73
|
+
this.#logger.warn(
|
|
74
|
+
{ error, activity: activity.id, inbox, attempts },
|
|
75
|
+
'Could not deliver activity due to unrecoverable server error'
|
|
76
|
+
)
|
|
77
|
+
await this.#jobQueue.fail(jobId, this.#workerId)
|
|
78
|
+
} else if (attempts >= DistributionWorker.#MAX_ATTEMPTS) {
|
|
85
79
|
this.#logger.warn(
|
|
86
80
|
{ error, activity: activity.id, inbox, attempts },
|
|
87
81
|
'Could not deliver activity due to server error; no more attempts'
|
|
88
82
|
)
|
|
89
83
|
await this.#jobQueue.fail(jobId, this.#workerId)
|
|
90
84
|
} else {
|
|
91
|
-
const delay =
|
|
85
|
+
const delay = this.#retryDelay(error.headers, attempts)
|
|
92
86
|
this.#logger.warn(
|
|
93
87
|
{ error, activity: activity.id, inbox, attempts, delay },
|
|
94
88
|
'Could not deliver activity due to server error; will retry'
|
|
@@ -110,7 +104,7 @@ export class DistributionWorker {
|
|
|
110
104
|
}
|
|
111
105
|
this.#logger.warn({ err, jobId }, 'Error delivering to bot')
|
|
112
106
|
if (jobId) {
|
|
113
|
-
const delay =
|
|
107
|
+
const delay = this.#retryDelay(null, attempts ?? 1)
|
|
114
108
|
this.#logger.warn(
|
|
115
109
|
{ err, jobId, attempts, delay },
|
|
116
110
|
'Retrying job after a delay'
|
|
@@ -121,6 +115,20 @@ export class DistributionWorker {
|
|
|
121
115
|
}
|
|
122
116
|
}
|
|
123
117
|
|
|
118
|
+
#retryDelay (headers, attempts) {
|
|
119
|
+
if (headers?.['retry-after']) {
|
|
120
|
+
this.#logger.debug('using retry-after header')
|
|
121
|
+
const retryAfter = headers['retry-after']
|
|
122
|
+
if (/^\d+$/.test(retryAfter)) {
|
|
123
|
+
return parseInt(retryAfter, 10) * 1000
|
|
124
|
+
} else {
|
|
125
|
+
return new Date(retryAfter) - Date.now()
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
this.#logger.debug('exponential backoff')
|
|
129
|
+
return Math.round((2 ** (attempts - 1) * 1000) * (0.5 + Math.random()))
|
|
130
|
+
}
|
|
131
|
+
|
|
124
132
|
stop () {
|
|
125
133
|
this.#running = false
|
|
126
134
|
}
|