feat: add DriverWithReceive interface for batch-consuming queue drivers#1435
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds an optional batch-receive capability to the queue driver contract and updates the queue worker to use it when available (targeting high-throughput drivers like Kafka).
Changes:
- Introduces
DriverWithReceivein the queue driver contracts to support blocking batch consumption viaReceive(ctx, queue, count). - Refactors
Worker.run()to choose between aReceive-based loop and the existingPop-based loop. - Extracts shared reserved-job handling into
processReservedJobfor reuse across both consumption strategies.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
queue/worker.go |
Adds Receive-based consumption loop, selects between Receive and Pop, and factors out shared job-processing logic. |
contracts/queue/driver.go |
Defines the optional DriverWithReceive interface to enable batch blocking receives. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
hwbrzzl
left a comment
There was a problem hiding this comment.
Thanks, a few questions.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1435 +/- ##
==========================================
+ Coverage 68.76% 68.78% +0.02%
==========================================
Files 361 361
Lines 27776 27829 +53
==========================================
+ Hits 19099 19143 +44
- Misses 7831 7839 +8
- Partials 846 847 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot summarize this PR |
This PR adds a Key changes:
|
Adds an optional
DriverWithReceiveinterface to support high-throughput drivers (e.g., Kafka) that benefit from blocking batch consumption rather than single-job polling.Contract
Workers detect this interface at runtime and dispatch to
runWithReceiveinstead ofrunWithPop.Worker changes (
queue/worker.go)runWithReceive: blocking batch loop with 5s per-call timeout derived fromshutdownCtx; exponential backoff (100ms–3.2s) on errors/empty batches;context.Canceledskips sleep and re-checks shutdown immediatelyrunWithPop: goroutine-local backoff state (eliminates data race oncurrentDelay);time.Sleepreplaced withselectonshutdownCtx.Done()for prompt shutdownshutdownCtx/shutdownCancelreinitialized inRun()to support restart;jobWgtracks the receive loop soShutdown()waits before closingfailedJobChanrun(): failed-job processor goroutine started once, shared by both paths;processReservedJobextracted as shared helperTests (
queue/worker_test.go)New
Test_runWithReceivesuite covering: empty batch, receive error, single job, batch jobs, and shutdown-waits-for-in-flight-jobs.