Skip to content

[13.x] Support #[Delay] attribute on queued mailables#59577

Closed
sumaiazaman wants to merge 2 commits intolaravel:13.xfrom
sumaiazaman:fix/mailable-delay-attribute
Closed

[13.x] Support #[Delay] attribute on queued mailables#59577
sumaiazaman wants to merge 2 commits intolaravel:13.xfrom
sumaiazaman:fix/mailable-delay-attribute

Conversation

@sumaiazaman
Copy link
Copy Markdown
Contributor

Summary

The #[Delay] attribute is supported for queued jobs (Bus\Dispatcher), event listeners (Events\Dispatcher), and notifications (NotificationSender) via getAttributeValue(), but queued mailables only check the $delay property and ignore the attribute entirely.

This means the following does not work as expected:

use Illuminate\Queue\Attributes\Delay;

#[Delay(30)]
class WelcomeEmail extends Mailable implements ShouldQueue
{
    // The #[Delay] attribute is ignored — mailable is queued immediately
}

Changes

  • Added ReadsQueueAttributes trait to Mailable
  • Updated Mailable::queue() to use getAttributeValue() for reading delay, consistent with how Bus\Dispatcher::pushCommandToQueue(), Events\Dispatcher::queueHandler(), and NotificationSender::queueNotification() handle the #[Delay] attribute
  • The $delay property still takes precedence when explicitly set (not default), matching the behavior of getAttributeValue()

Test Plan

  • Added test to verify #[Delay] attribute is respected on queued mailables
  • Added test to verify property override still takes precedence over attribute
  • Existing queued mailable tests still pass

The #[Delay] attribute is supported for queued jobs, event listeners,
and notifications via getAttributeValue(), but queued mailables only
check the $delay property and ignore the attribute entirely.

This adds the ReadsQueueAttributes trait to Mailable and uses
getAttributeValue() in the queue() method, consistent with how
Bus\Dispatcher, Events\Dispatcher, and NotificationSender handle
the #[Delay] attribute.
@taylorotwell
Copy link
Copy Markdown
Member

Use the support trait.

@sumaiazaman
Copy link
Copy Markdown
Contributor Author

Use the support trait.

Updated to use ReadsClassAttributes support trait instead of ReadsQueueAttributes. Thanks for the feedback!

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