Title: fix: keep RabbitMQ delay queues per priority and publish before rejecting by gr8man · Pull Request #107 · codeigniter4/queue · GitHub
Open Graph Title: fix: keep RabbitMQ delay queues per priority and publish before rejecting by gr8man · Pull Request #107 · codeigniter4/queue
X Title: fix: keep RabbitMQ delay queues per priority and publish before rejecting by gr8man · Pull Request #107 · codeigniter4/queue
Description: Description Delayed delivery in RabbitMQHandler (push() with a delay and later()) had three problems. A single delay queue was shared by every priority. queue_{queue}_delay was declared once with x-dead-letter-routing-key fixed to the default priority routing key ({queue}.default). A delayed job with a non-default priority was dead-lettered into the default bucket after its TTL, so priority ordering was lost. In addition, a second process declaring the same argument set differently received PRECONDITION_FAILED (406) and lost its channel. later() rejected the original message before the replacement was published. basic_nack() was called before publishDelayedMessage(). If the publish failed, the original message was already gone — a silently lost job. publishDelayedMessage() relied on the exchange already existing and re-bound the delay queue on every publish. later() can be called by a worker that never went through push(), so the exchange (and its bindings) might not exist at that point. In addition, push() only reset $this->priority/$this->delay on the success path, so a failed push could leak state into the next operation. Changes src/Handlers/RabbitMQHandler.php Delay queues are now created per logical queue and priority: queue_{queue}_{priority}_delay (getDelayQueueName($queue, $priority)). The x-dead-letter-routing-key therefore always targets the priority bucket the job belongs to. The legacy queue_{queue}_delay name is kept only for cleanup (getLegacyDelayQueueName()). later() publishes the delayed copy first and only then calls basic_nack() on the original message. If publishing throws, the original message stays unacknowledged and is not lost. publishDelayedMessage() now ensures the exchange exists (declareExchange()), declares and binds the per-priority delay queue only once (guarded by $this->declaredQueues). declareExchange() binds the priority queues together with the exchange declaration instead of re-binding them on every publish. clearQueue() purges the delay queue of every priority (before the priority queues) and also purges the legacy delay queue, so jobs scheduled before this change cannot leak back after a clear. push() resets priority and delay in a finally block so the state can never leak into the next push. Testing Added tests/RabbitMQHandlerUnitTest.php, which exercises the handler logic without a live broker (channel and config are mocked): testGetDelayQueueNameIncludesPriority() testPublishDelayedMessageDeclaresPerPriorityQueueAndDeadLetterRouting() — asserts that x-dead-letter-routing-key matches the priority bucket. testPublishDelayedMessageBindsDelayQueueOnlyOnceAcrossPublications() testLaterPublishesDelayedMessageBeforeRejectingOriginalMessage() — asserts the publish/basic_nack ordering. testLaterDoesNotRejectOriginalMessageWhenPublishingDelayedFails() testClearQueuePurgesDelayQueuesForEachPriority() — including the legacy delay queue. testPushResetsPriorityAndDelayInFinallyBlockOnFailure() The existing tests/RabbitMQHandlerTest.php and tests/RabbitMQDelayTest.php suites still pass against the integration setup. Verified locally on PHP 8.5 with PHPUnit 11.5: phpunit ....... OK (237 tests, 682 assertions, 27 skipped) phpstan ....... [OK] No errors psalm ......... No errors found php-cs-fixer .. 0 of 76 files would be fixed
Open Graph Description: Description Delayed delivery in RabbitMQHandler (push() with a delay and later()) had three problems. A single delay queue was shared by every priority. queue_{queue}_delay was declared once with ...
X Description: Description Delayed delivery in RabbitMQHandler (push() with a delay and later()) had three problems. A single delay queue was shared by every priority. queue_{queue}_delay was declared once with ...
Opengraph URL: https://github.com/codeigniter4/queue/pull/107
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:f7e40b29-84e6-a52a-0487-6bab28426d3f |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | E610:1BB1CE:1B669B:253B09:6AFD4F29 |
| html-safe-nonce | c1dcf602c2c68bfc388315ba268cc7b2ef8a8c86a80d1fb407aee6bf3d649647 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNjEwOjFCQjFDRToxQjY2OUI6MjUzQjA5OjZBRkQ0RjI5IiwidmlzaXRvcl9pZCI6IjcyNDczMzE4NTAwMzk2NzY3MTMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 26bd18ff001a970a8073f75a09ed7a9b50b976c056405db2470ed4cd061ad380 |
| hovercard-subject-tag | pull_request:5251084996 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/codeigniter4/queue/pull/107/files |
| twitter:image | https://avatars.githubusercontent.com/u/5325117?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/5325117?s=400&v=4 |
| og:image:alt | Description Delayed delivery in RabbitMQHandler (push() with a delay and later()) had three problems. A single delay queue was shared by every priority. queue_{queue}_delay was declared once with ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 66653c2e55a6fff2930be1bdf07ee4f8aa137e3956d056c822563be6f878755e |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/codeigniter4/queue git https://github.com/codeigniter4/queue.git |
| octolytics-dimension-user_id | 44521256 |
| octolytics-dimension-user_login | codeigniter4 |
| octolytics-dimension-repository_id | 704648363 |
| octolytics-dimension-repository_nwo | codeigniter4/queue |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 704648363 |
| octolytics-dimension-repository_network_root_nwo | codeigniter4/queue |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b6f01f7cb9f35f8c09949773241a3d49dd04b340 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width