Skip to content

Conversation

@MagnusDot
Copy link

@MagnusDot MagnusDot commented Nov 18, 2025

This PR adds two fluent methods to the Queueable trait to configure job retry behavior:

  • retryWithDelay($delays) - Set custom backoff delays for job retries
  • retryUntil($datetime) - Set the timestamp until which a job can be retried

These methods provide a cleaner, more fluent API for configuring retry behavior, consistent with other methods like delay(), onQueue(), and onConnection().

Changes

  • Added $backoff and $retryUntil properties to the Queueable trait
  • Added retryWithDelay($delays) method that accepts integers, arrays, DateTimeInterface, or DateInterval
  • Added retryUntil($datetime) method that accepts DateTimeInterface or timestamp (int)
  • Both methods return $this for method chaining
  • Added comprehensive tests covering all supported parameter types and integration with the queue system

Usage

// Set custom retry delays
MyJob::dispatch()
    ->retryWithDelay([10, 30, 60, 120])
    ->retryUntil(now()->addHours(2));

// Or with a single delay
MyJob::dispatch()->retryWithDelay(60);

// Chain with other methods
MyJob::dispatch()
    ->retryWithDelay([10, 30, 60])
    ->retryUntil(now()->addDay())
    ->onQueue('high')
    ->onConnection('redis');## Testing
  • All existing tests pass
  • Added new tests covering

Backward Compatibility

This change is fully backward compatible. The existing behavior of setting $backoff and $retryUntil properties directly or via methods in job classes remains unchanged. These new methods simply provide a more convenient fluent API.

Adds `retryWithDelay` and `retryUntil` methods to the `Queueable` trait.
These methods allow developers to define custom retry logic for queued jobs,
improving resilience and control over job execution.
Also introduces corresponding properties to store the configuration.

Removes redundant comment

Removes a comment in `QueueableTest.php` that is no longer necessary
after previous changes.

Allows retrieval of retryUntil value

Allows retrieving the current retryUntil value when no arguments are passed to the retryUntil method.

This is useful for inspecting the retryUntil value that has been set on a job.
@MagnusDot MagnusDot force-pushed the feature/queueable-retry-methods branch from 6f4a280 to 7a397d2 Compare November 18, 2025 11:16
@rodrigopedra
Copy link
Contributor

This is a breaking change for any jobs using the Queueable trait and already defining a typed $backoff or $retryUntil property.

class MyJob implements ShouldQueue 
{
    use Queueable;

    // this will break with the proposed change
    public int $backoff = 30;

    // ...
}

@taylorotwell
Copy link
Member

We don't need another way to do this imo.

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.

3 participants