Skip to content

Commit e496280

Browse files
authored
Rate limit r2 bulk put (#11367)
1 parent 6701036 commit e496280

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

.changeset/wide-women-jump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Rate limit r2 bulk put

packages/wrangler/src/r2/object.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,20 @@ export const r2BulkPutCommand = createCommand({
569569
}
570570
);
571571
} else {
572+
// Cloudflare API rate limits
573+
// 1200 requests per 5 minutes
574+
// We add some headroom (100 requests) for other API usage
575+
// ref: https://developers.cloudflare.com/fundamentals/api/reference/limits/
576+
const API_RATE_LIMIT_WINDOWS_MS = 5 * 60 * 1_000; // 5 minutes
577+
const API_RATE_LIMIT_REQUESTS = 1_200 - 100;
578+
572579
const accountId = await requireAuth(config);
573580

574-
const queue = new PQueue({ concurrency });
581+
const queue = new PQueue({
582+
concurrency,
583+
interval: API_RATE_LIMIT_WINDOWS_MS,
584+
intervalCap: API_RATE_LIMIT_REQUESTS,
585+
});
575586

576587
await queue.addAll(
577588
entries.map((entry, index) => async () => {

0 commit comments

Comments
 (0)