Repository navigation
fix(github-backup): paginate queue polling (#3476) #3484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import assert from "node:assert/strict"; | ||
| import { test } from "node:test"; | ||
| import worker from "../src/index.js"; | ||
|
|
||
| test("GET /queue forwards cursor and exposes KV pagination metadata", async () => { | ||
| const listCalls = []; | ||
| const values = new Map([ | ||
| ["ev:first", JSON.stringify({ id: "first", repo: "owner/first" })], | ||
| ["ev:second", JSON.stringify({ id: "second", repo: "owner/second" })], | ||
| ]); | ||
| const kv = { | ||
| async list(options) { | ||
| listCalls.push(options); | ||
| if (options.cursor === "page two/+") { | ||
| return { | ||
| keys: [{ name: "ev:second" }], | ||
| cursor: null, | ||
| list_complete: true, | ||
| }; | ||
| } | ||
| return { | ||
| keys: [{ name: "ev:first" }], | ||
| cursor: "page two/+", | ||
| list_complete: false, | ||
| }; | ||
| }, | ||
| async get(name) { | ||
| return values.get(name) ?? null; | ||
| }, | ||
| }; | ||
| const env = { GHB_EVENTS: kv, DRAIN_BEARER: "test-bearer" }; | ||
| const request = (cursor) => new Request( | ||
| "https://worker.test/queue" + (cursor === undefined | ||
| ? "" : "?cursor=" + encodeURIComponent(cursor)), | ||
| { headers: { Authorization: "Bearer test-bearer" } }, | ||
| ); | ||
|
|
||
| const first = await worker.fetch(request(undefined), env); | ||
| assert.equal(first.status, 200); | ||
| assert.deepEqual(await first.json(), { | ||
| events: [{ id: "first", repo: "owner/first" }], | ||
| cursor: "page two/+", | ||
| list_complete: false, | ||
| }); | ||
|
|
||
| const second = await worker.fetch(request("page two/+"), env); | ||
| assert.equal(second.status, 200); | ||
| assert.deepEqual(await second.json(), { | ||
| events: [{ id: "second", repo: "owner/second" }], | ||
| cursor: null, | ||
| list_complete: true, | ||
| }); | ||
| assert.deepEqual(listCalls, [ | ||
| { prefix: "ev:", limit: 500 }, | ||
| { prefix: "ev:", limit: 500, cursor: "page two/+" }, | ||
| ]); | ||
| }); | ||
|
|
||
| test("GET /queue still requires the bearer token", async () => { | ||
| let listed = false; | ||
| const response = await worker.fetch( | ||
| new Request("https://worker.test/queue"), | ||
| { GHB_EVENTS: { async list() { listed = true; return { keys: [] }; } }, DRAIN_BEARER: "secret" }, | ||
| ); | ||
| assert.equal(response.status, 401); | ||
| assert.equal(listed, false); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a backlog contains more than 1,000 ackable events, collecting every page makes
main()send all their IDs in a single/queue/ackrequest. That Worker handler performs one awaited KV delete per ID, but Cloudflare limits each invocation to 1,000 KV operations, so the request fails after partially deleting the batch and the drainer exits with an error. Previously, the 500-event polling limit kept acknowledgements below this ceiling. Split acknowledgements into bounded requests so multi-page backlogs can drain successfully.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed: acknowledgements are now sent through ack_events(), which batches ids at ACK_BATCH_SIZE = 500 per /queue/ack request — well under the Worker's 1,000-KV-operation invocation limit — so multi-page backlogs drain completely instead of failing mid-batch. Regression test in test_drain_queue.py case 15: 1,200 ackable events produce 3 bounded ack requests with every event acked (63/63 checks pass).