iteration-cli 0.14.1 → 0.14.2
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/dist/cli.js +31 -13
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -17845,12 +17845,18 @@ async function scanSourceOnce(config2, paths, signal) {
|
|
|
17845
17845
|
}
|
|
17846
17846
|
};
|
|
17847
17847
|
}
|
|
17848
|
+
function retryAfterMs(response) {
|
|
17849
|
+
const header = response.headers.get("retry-after");
|
|
17850
|
+
if (header === null) return null;
|
|
17851
|
+
const milliseconds = /^\d+$/.test(header) ? Number(header) * 1e3 : Date.parse(header) - Date.now();
|
|
17852
|
+
return Number.isFinite(milliseconds) ? Math.max(1e3, Math.min(milliseconds, 3e5)) : 5e3;
|
|
17853
|
+
}
|
|
17848
17854
|
async function uploadPendingOnce(config2, paths, fetcher = collectorFetch, signal, onAcknowledged) {
|
|
17849
17855
|
let uploaded = 0;
|
|
17850
17856
|
for (let attempt = 0; attempt < MAX_UPLOADS_PER_TICK; attempt += 1) {
|
|
17851
17857
|
signal?.throwIfAborted();
|
|
17852
17858
|
const batch = await nextBatch(paths, MAX_UPLOAD_BYTES);
|
|
17853
|
-
if (batch.length === 0) return uploaded;
|
|
17859
|
+
if (batch.length === 0) return { uploaded, retryAfterMs: null };
|
|
17854
17860
|
const body = JSON.stringify({ events: batch });
|
|
17855
17861
|
if (Buffer.byteLength(body, "utf8") > MAX_REQUEST_BYTES) {
|
|
17856
17862
|
throw new Error("Queued trace batch exceeds the upload request limit.");
|
|
@@ -17875,6 +17881,10 @@ async function uploadPendingOnce(config2, paths, fetcher = collectorFetch, signa
|
|
|
17875
17881
|
{ cause: error2 }
|
|
17876
17882
|
);
|
|
17877
17883
|
}
|
|
17884
|
+
if (response.status === 429) {
|
|
17885
|
+
await response.body?.cancel();
|
|
17886
|
+
return { uploaded, retryAfterMs: retryAfterMs(response) ?? 5e3 };
|
|
17887
|
+
}
|
|
17878
17888
|
if (response.status !== 202) {
|
|
17879
17889
|
throw new TraceUploadError(
|
|
17880
17890
|
"http",
|
|
@@ -17901,12 +17911,14 @@ async function uploadPendingOnce(config2, paths, fetcher = collectorFetch, signa
|
|
|
17901
17911
|
await acknowledgeEvents(new Set(parsed.value.acceptedEventIds), paths);
|
|
17902
17912
|
onAcknowledged?.();
|
|
17903
17913
|
uploaded += batch.length;
|
|
17914
|
+
const pause = retryAfterMs(response);
|
|
17915
|
+
if (pause !== null) return { uploaded, retryAfterMs: pause };
|
|
17904
17916
|
}
|
|
17905
|
-
return uploaded;
|
|
17917
|
+
return { uploaded, retryAfterMs: null };
|
|
17906
17918
|
}
|
|
17907
17919
|
async function collectorTick(config2, paths, fetcher = collectorFetch, signal, onAcknowledged) {
|
|
17908
17920
|
await redactPendingOutbox(paths);
|
|
17909
|
-
let
|
|
17921
|
+
let upload = await uploadPendingOnce(
|
|
17910
17922
|
config2,
|
|
17911
17923
|
paths,
|
|
17912
17924
|
fetcher,
|
|
@@ -17914,19 +17926,23 @@ async function collectorTick(config2, paths, fetcher = collectorFetch, signal, o
|
|
|
17914
17926
|
onAcknowledged
|
|
17915
17927
|
);
|
|
17916
17928
|
const scan = await outboxSize(paths) >= SCAN_PAUSE_OUTBOX_BYTES ? { discovered: 0, caughtUp: false, history: null } : await scanSourceOnce(config2, paths, signal);
|
|
17917
|
-
|
|
17918
|
-
|
|
17919
|
-
|
|
17920
|
-
|
|
17921
|
-
|
|
17922
|
-
|
|
17923
|
-
|
|
17929
|
+
if (upload.retryAfterMs === null) {
|
|
17930
|
+
const next = await uploadPendingOnce(
|
|
17931
|
+
config2,
|
|
17932
|
+
paths,
|
|
17933
|
+
fetcher,
|
|
17934
|
+
signal,
|
|
17935
|
+
onAcknowledged
|
|
17936
|
+
);
|
|
17937
|
+
upload = { ...next, uploaded: upload.uploaded + next.uploaded };
|
|
17938
|
+
}
|
|
17924
17939
|
return {
|
|
17925
17940
|
discovered: scan.discovered,
|
|
17926
|
-
uploaded,
|
|
17941
|
+
uploaded: upload.uploaded,
|
|
17927
17942
|
outboxBytes: await outboxSize(paths),
|
|
17928
17943
|
historyCaughtUp: scan.caughtUp,
|
|
17929
|
-
history: scan.history
|
|
17944
|
+
history: scan.history,
|
|
17945
|
+
retryAfterMs: upload.retryAfterMs ?? 0
|
|
17930
17946
|
};
|
|
17931
17947
|
}
|
|
17932
17948
|
|
|
@@ -19034,7 +19050,9 @@ async function runCollector(directory, expectedSource) {
|
|
|
19034
19050
|
})
|
|
19035
19051
|
);
|
|
19036
19052
|
}
|
|
19037
|
-
retryDelayMs = 5e3;
|
|
19053
|
+
retryDelayMs = Math.max(5e3, result.retryAfterMs);
|
|
19054
|
+
if (result.retryAfterMs > 0)
|
|
19055
|
+
retryDelayMs += Math.floor(Math.random() * 1e3);
|
|
19038
19056
|
} catch (error2) {
|
|
19039
19057
|
if (controller.signal.aborted) break;
|
|
19040
19058
|
if (!trialSettled && runtimeVersion !== void 0) {
|