skip to Main Content

How can I set up Laravel queues using database/Redis connection so that job does not fail for the Mailtrap rate limit of five emails per 10 secs? For example, I tried to execute six jobs with two workers using Redis.
But the 6th job failed with the error below in failed jobs table.

Too many emails per second.

Redis::throttle('key')->allow(5)->every(10)->then(function () {
    $email = new WelcomeEmail();
    Mail::to('[email protected]')->send($email);
}, function () {
    return $this->release(7);
});

2

Answers


  1. Chosen as BEST ANSWER

    We have two queues, q1(waiting) and q2(processing). The publisher push tasks on q1, the worker then pops a task off of q1 and push it into q2. After processing by worker is completed, the task is removed from q2. if q2 task crashed, failed or takes too long to completed the task. The task is then transferred to q1 to be picked again by worker

    Example with database: Processing job Queue with two worker for eleven jobs with default timeout of 3

    So this works fine with two workers only, for four workers it will fail due to early completion. we need to increase no of tries, as 3 tries exhausted within current 10 sec limit.


  2. Mailtrap only allows 5 mails per 10 seconds for free and individual. You can check their pricing page. If you buy their team subscription then it will allow you to send 25 mails per 10 seconds BUT it will cost you 24.99 USD

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search