qase-javascript-commons 2.4.11 → 2.4.12

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 CHANGED
@@ -1,3 +1,9 @@
1
+ # qase-javascript-commons@2.4.12
2
+
3
+ ## What's new
4
+
5
+ Improved the retry mechanism for uploading attachments.
6
+
1
7
  # qase-javascript-commons@2.4.11
2
8
 
3
9
  ## What's new
@@ -145,6 +145,12 @@ class ClientV1 {
145
145
  return [];
146
146
  }
147
147
  const uploadedHashes = [];
148
+ // Add initial random delay to spread out requests from different workers/shard
149
+ // This helps prevent all workers from hitting the API at the same time
150
+ if (attachments.length > 0) {
151
+ const initialJitter = Math.random() * 500; // 0-500ms random delay
152
+ await this.delay(initialJitter);
153
+ }
148
154
  for (let i = 0; i < attachments.length; i++) {
149
155
  const attachment = attachments[i];
150
156
  if (!attachment) {
@@ -165,7 +171,10 @@ class ClientV1 {
165
171
  // Add delay between requests to avoid rate limiting
166
172
  // Skip delay after the last attachment
167
173
  if (i < attachments.length - 1) {
168
- await this.delay(100); // 100ms delay between requests
174
+ // Increased delay with random jitter to prevent synchronization
175
+ const baseDelay = 1000; // 1000ms (1 second) base delay
176
+ const jitter = Math.random() * 300; // 0-300ms random jitter
177
+ await this.delay(baseDelay + jitter);
169
178
  }
170
179
  }
171
180
  return uploadedHashes;
@@ -193,7 +202,12 @@ class ClientV1 {
193
202
  if (error.response?.status === 429) {
194
203
  if (attempt < maxRetries) {
195
204
  const retryAfter = this.getRetryAfter(error);
196
- const waitTime = retryAfter ?? delay;
205
+ const baseWaitTime = retryAfter ?? delay;
206
+ // Add jitter (random delay) to prevent all workers from retrying simultaneously
207
+ // Jitter is 10-30% of the wait time to spread out retry attempts
208
+ const jitterPercent = 0.1 + Math.random() * 0.2; // 10-30%
209
+ const jitter = baseWaitTime * jitterPercent;
210
+ const waitTime = Math.floor(baseWaitTime + jitter);
197
211
  this.logger.logDebug(`Rate limit exceeded (429) for attachment "${attachmentName}". ` +
198
212
  `Retrying in ${waitTime}ms (attempt ${attempt + 1}/${maxRetries})`);
199
213
  await this.delay(waitTime);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qase-javascript-commons",
3
- "version": "2.4.11",
3
+ "version": "2.4.12",
4
4
  "description": "Qase JS Reporters",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",