Do not limit all your queues, but push those queued notifications to separate named queue which you will add rate to in supervisor configuration.
Notification Queue Throttling
TLDR: how can I throttle my emails queued via Notifications
Slightly longer: I tried to RTFM and I can see how to throttle my Redis Queue via Jobs. But if I'm using Notification + Queable, I don't see how I can throttle. It would be nice if I could set my worker to work at a certain rate... php artisan queue:work --rate=5 to limit it to 5 jobs per second or whatever. I see queue:work has a sleep option, but it's in seconds, which would be too slow. My AWS SES email limit is currently 14/second, so ideally I'd be able to work my queue just under that.
Longer/Full Details: I'm using Laravel 7.x and hosting on AWS via Forge. I'm working on sending notifications when a user comments on something.
Current flow:
Someone posts a comment, which fires an event "CommentPostedEvent". A listener "SendCommentPosted" queues an intermediate job "QueueUserNotificationsJob" because I found that doing Notification::send() with a large group of users was too slow. So QueueUserNotificationsJob fetches the users that need to be notified and calls Notification::send() which is a Queuable Notification "CommentPostedNotification".
"CommentPostedNotification" (again, queable) has multiple channels: databse broadcast, mail, sms etc.
I want my database and broadcast channels to just fire off as quickly as possible, but I want to throttle my mail channel. So step 1 was specifying queue by channel. I did this by updating Laravel's NotificationSender (I sent in a PR, but have my doubts it'll be accepted. It's my first: https://github.com/laravel/framework/pull/32673/files -- it works for me so I'll use it anyway for now).
So I have my email notifications being queued on a separate queue now. But I just can't seem to figure out if there's a way to rate limit working that queue.
Thoughts? Happy to hear any and all, this is my first time working with Notifications in Laravel; thought it looked nice, but I've hit some snags.
Thanks! Brian
Please or to participate in this conversation.