Skip to content

Conversation

sylvesterdamgaard
Copy link
Contributor

This PR improves queue metric support by adding methods to retrieve:

  • Pending jobs
  • Delayed (scheduled) jobs
  • Reserved jobs
  • Oldest pending job (where supported — not available for SQS and Beanstalkd)

It also fixes inconsistencies in the size() method. Previously, different queue drivers returned different values — some only counted pending jobs, while others included all jobs.

Now, size() consistently returns the total number of jobs (pending + delayed + reserved) across all supported drivers.

Previous behavior:

Driver size() Before size() Now
Database All jobs ✅ All jobs ✅
Redis All jobs ✅ All jobs ✅
SQS Pending only ❌ All jobs ✅
Beanstalkd Pending only ❌ All jobs ✅

⚠️ Note on --max behavior in queue:monitor

The --max option currently uses the size() method to determine when to trigger alerts.

Since size() now consistently returns the total job count (pending + delayed + reserved), this may lead to different behavior compared to earlier versions — especially if delayed or reserved jobs are significant.

In most cases, it's more meaningful to base alerts on pending jobs only.

This PR does not change how --max works, but it may be worth considering updating queue:monitor to optionally use sizePending() instead.


🧪 Testing Improvements

The FakeQueue has been updated to support testing of job state transitions:

  • Simulates jobs transitioning between pending, delayed, and reserved
  • Enables more accurate and complete test coverage for queue behavior

…served size and oldest job where available.

Add the new metrics to the monitor command output.
Update the QueueFake driver to support testing delayed jobs and reserved jobs.
The size method now follows the convention of all other drivers where size() returns the total number of jobs and not just pending jobs
@taylorotwell taylorotwell merged commit 9e39547 into laravel:12.x Jun 12, 2025
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants