Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Allow customised implementation of the SendQueuedMailable job #45040

Merged
merged 1 commit into from Nov 21, 2022

Conversation

JayBizzle
Copy link
Contributor

What?

Allow us to bind a different implementation of the built-in SendQueuedMailable job.

For example...

app()->bind(\Illuminate\Mail\SendQueuedMailable::class, function($app, $params) {
    return new \App\Jobs\SendQueuedMailable($params['mailable']);
});

Why?

We have a lot of emails that we send by implementing ShouldQueue on the Mailable class. In all instances, we would like to use our own implementation of the handle() method of the built-in SendQueuedMailable job, which will enable us to handle exceptions in a more granular manner.

For example, most of our emails have a backoff() strategy and a retryUntil() value. Sometimes, we receive an exception via our 3rd party email provider which we know means the email is never going to be sent, so there is no point retrying it. We would just like to permanently fail that job at that point.

Something like...

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle(MailFactory $factory)
    {
        try {
            $this->mailable->send($factory);
        } catch (\Exception $e) {
            if (Str::contains($e->getMessage(), 'Permanent failure')) {
                $this->fail();
            }
        }
    }

I know we could use our own job to do this, but it requires our team to always remember to dispatch the custom job, rather than just calling send() on the Mailable.

@taylorotwell taylorotwell merged commit e5a0ee6 into laravel:9.x Nov 21, 2022
@JayBizzle JayBizzle deleted the patch-1 branch November 21, 2022 20:32
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.

None yet

2 participants