Repository navigation
feat(queue): bound the Redis recovery sweep by attempts and age - #14689
Conversation
|
Review complete. 🟡 1 medium 📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to🟡 Medium — // packages/queue/src/Broker/Redis.php
508 $dead = ($maxAttempts !== null && $job->getAttempts() >= $maxAttempts)
509 || ($newerThan !== null && $job->getTimestamp() < $now - $newerThan);
510 $moved = $this->script($this->commands, 'reclaim', [
Adds poison-claim handling to the Redis queue broker:
Reviewed commit: 36b6582 |
🟢 Tier S · Ready to mergeAdds optional attempt and age limits to Redis broker recovery and passes them from
📂 Walkthrough · 3
Reviewed |
Security rulesNo new WARNING or ERROR findings from security rules. 19 existing findings tracked in
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
maintain() reaped every stranded claim older than reapAfter with no attempt or age limit, and the constructor exposed only reapAfter. A processing list left behind by a release without the sweep was replayed in full on upgrade: months-old jobs ran again, and ones whose payload shape had since changed failed on decode. reapMaxAttempts and reapMaxAge pass through to reap() as maxAttempts and newerThan, so the sweep parks those claims on the dead queue instead. Both default to null, which keeps the current behaviour. reapMaxAge must exceed reapAfter, because every claim the sweep reaches is at least that old and a lower ceiling would park all of them.
36b6582 to
59d8ce8
Compare
What does this PR do?
Adds two optional limits to the Redis broker's automatic recovery sweep:
reapMaxAttemptsandreapMaxAge.maintain()callsreap()every 60s and requeues up to 1,000 stranded claims older thanreapAfter. It passes no attempt limit and no age limit, and the constructor exposes onlyreapAfter, so a consumer can't bound the sweep.reap()already supports both limits (maxAttempts,newerThan) and parks matching claims on thedeadqueue. The sweep just never passed them.That broke Appwrite Edge's upgrade to queue 6 (appwrite-labs/edge#1525, reverted in appwrite-labs/edge#1564):
utopia-queue.processing.v1-regionsheld about 9,060 such entries going back several months.cdn_purgejobs used a payload shape the current code no longer accepts, so they failed on decode and landed onfailed.Change
Broker\Redis::__constructgets?int $reapMaxAttempts = nulland?int $reapMaxAge = null(seconds).maintain()passes them toreap()asmaxAttemptsandnewerThan.null, which keeps the current behaviour.reapMaxAttempts < 1, and areapMaxAgeat or belowreapAfter. Every claim the sweep reaches is already at leastreapAfterold, so a ceiling that low would park every claim and recover none.Test Plan
tests/E2E/RedisBrokerRecoveryTest.php, against the package's compose Redis:testMaintainParksClaimsOlderThanReapMaxAge: a claim backdated an hour, withreapMaxAge: 600, goes todead, not back to the queue.testMaintainParksClaimsPastReapMaxAttempts: withreapMaxAttempts: 1, the first stranding is requeued (attempts 0 → 1) and the second is parked ondead.maintain()wiring reverted, both fail (Failed asserting that 0 is identical to 1, on the dead-queue size). With it, all 24 tests in the class pass.tests/RedisReapLimitsTest.php(unit): covers the two constructor checks, and that valid limits are accepted.rector --dry-run,pint --testandphpstanare clean forpackages/queue.origin/mainwithout this change.Related PRs and Issues
Once this is released, edge will set
reapMaxAttempts: 3, reapMaxAge: 172800and re-apply the upgrade.Checklist