My application is hosted on a shared hosting platform which has a limit of 200 emails per hour.
My application is running Database Connection Driver and I have 3000 jobs in the jobs table.
I want to limit this queue to only send 1 email every 30 seconds or 1 minute to ensure there are no issues with my hosting.
Research: I tried this tutorial's delay, this question's rate limiting but no response, this laravel documentation's delay job, but nothing worked.
Question: Is there a way to limit the queues in database queue connection like in redis queue connection , i.e.
// Allow only 1 email every 30 seconds Redis::throttle('any_key')->allow(1)->every(30)->then(function () { Mail::to($this->email)->send(new NotificationEmail($this->data) ); Log::info('Emailed order ' . $this->email); }, function () { // Could not obtain lock; this job will be re-queued return $this->release(2); });
My implementation: Delay only the first job and then send the others immediately
public function sendEmailNotification($email,$data) { //Send email to user and to admin $email_job = (new ProcessEmailNotificationJob($email,$data))->delay(now()->addSeconds(30)); if($this->dispatch($email_job)){ return true; } else{ return false; } }
**ENV file:**
BROADCAST_DRIVER=log CACHE_DRIVER=file QUEUE_CONNECTION=database SESSION_DRIVER=file SESSION_LIFETIME=120 MEMCACHED_HOST=127.0.0.1
Have you run php artisanqueue:listen? If so, please check my code below maybe it will help
In the controller:
SendMailJob Class