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

Mailable does not support releasing the job back to queue #43571

Closed
ankurk91 opened this issue Aug 6, 2022 · 2 comments
Closed

Mailable does not support releasing the job back to queue #43571

ankurk91 opened this issue Aug 6, 2022 · 2 comments

Comments

@ankurk91
Copy link
Contributor

ankurk91 commented Aug 6, 2022

  • Laravel Version: 9.x (latest)
  • PHP Version: 8.1
  • Database Driver & Version: MySql 8.0.28
  • Cache Driver: Redis 6.2

Description:

Mailable class supports Job middleware but does not allow to release the job back to queue

Steps To Reproduce:

  • Create a Mailable class
  • Implement a middleware which release the job back to queue, see example
  • Notice that $job->release(5) wont work, since method is not available

Mail class

<?php 
namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Mail\Mailable;
use App\Jobs\Middleware\RateLimitEmail;

class DripCampaignEmail extends Mailable implements ShouldQueue
{
    use Queueable, SerializesModels;
   
   public function middleware(): array
    {
        return [new RateLimitEmail()];
    }

     public function build()
    {
       // your stuff
    }
  
}

Middleware class

<?php

<?php

namespace App\Jobs\Middleware;

use Closure;
use Illuminate\Support\Facades\Redis;

class RateLimitEmail
{
    public function handle($job, Closure $next): void
    {
        Redis::connection()
            ->throttle('rate_limit_lock_job:'.get_class($job))
            ->block(0)
            ->allow(10) // 10 outgoing emails per second
            ->every(1)
            ->then(function () use ($job, $next) {
                $next($job);
            }, function () use ($job) {
                $job->release(5); // wont work
            });
    }
}

Any help would be appropriated .

@driesvints
Copy link
Member

Hey there,

Can you first please try one of the support channels below? If you can actually identify this as a bug, feel free to open up a new issue with a link to the original one and we'll gladly help you out.

Thanks!

@ankurk91
Copy link
Contributor Author

ankurk91 commented Aug 8, 2022

I reported a broken feature in framework which seems to be a bug, and was introduced in PR:
#37568
By @themsaid

The PR demonstrate the usage via RateLimit middleware, which is not working property in Mailables.

I can create a reproduction repo if you want to.

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

No branches or pull requests

2 participants