-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
Middleware cannot release SendQueuedMailable again #44123
Comments
I needed this recently, I extended Then in the mailables I added a custom trait that overrode I also tweaked how middleware is handled as on the original I didn't try a PR at the time as I thought my use-case might be a corner case. For reference here is: my custom job "wrapper"<?php
namespace App\Jobs;
use Illuminate\Mail\SendQueuedMailable;
use Illuminate\Queue\InteractsWithQueue;
class MailableJob extends SendQueuedMailable
{
use InteractsWithQueue;
public bool $failOnTimeout = true;
public function middleware(): array
{
// read job middleware from wrapped mailable
return \array_merge(
\method_exists($this->mailable, 'middleware') ? $this->mailable->middleware() : [],
$this->mailable->middleware ?? [],
);
}
public function backoff(): array
{
return [60, 105, 120];
}
public function retryUntil(): ?\DateTimeInterface
{
if (\method_exists($this->mailable, 'retryUntil')) {
return $this->mailable->retryUntil();
}
return null;
}
} and the trait I add to my mailables to use my custom job class intead of `SendQueuedMailable`<?php
namespace App\Jobs;
trait UsesMailableJob
{
protected function newQueuedJob(): MailableJob
{
return new MailableJob($this);
}
} Just for completeness, in my use case I needed to use the following job middleware on some mailables:
I know there are best tools for monitoring, but for this specific project alerting by email was a requirement. |
I reported the issue in past @driesvints How can we (reporters) improve so that such issues get attention by Laravel team. |
@ankurk91 like I suggested on the issue, try a support channel first and get confirmation by others that it's an actual bug. Then repost the issue with links to those forum threads. |
@driesvints Thanks, i would prefer to create a minimal reproduction and share the git repo link. |
Description:
It looks like the
Illuminate\Queue\InteractsWithQueue
trait is missing onIlluminate\Mail\SendQueuedMailable
, which results in an PHP error when using middleware like #37568Steps To Reproduce:
Tested with
QUEUE_CONNECTION
set todatabase
andsync
, andMAIL_MAILER
set tolog
andsmtp
\Illuminate\Support\Facades\Mail::send(new \App\Mail\RandomMail());
\Illuminate\Support\Facades\Mail::send(new \App\Mail\RandomMail());
The text was updated successfully, but these errors were encountered: