bensheldon / good_job

Multithreaded, Postgres-based, Active Job backend for Ruby on Rails.
https://goodjob-demo.herokuapp.com/
MIT License
2.65k stars 195 forks source link

Using concurrency controls with ActionMailer #1385

Open drale2k opened 3 months ago

drale2k commented 3 months ago

@bensheldon after your help on Slack i can confirm this works fine and i think adding it to the docs will help others in the future.

config/initializers/good_job.rb

Rails.application.configure do
  ActionMailer::MailDeliveryJob.include GoodJob::ActiveJobExtensions::Concurrency
  ActionMailer::MailDeliveryJob.good_job_control_concurrency_with(
   perform_throttle: [ 2, 2.second ]
  )
end

In my case perform_throttle: [ 1, 1.second ] did not work as expected. It would send more than 1 per second and i would hit the rate limit on the Resend API. 2 in 2 seconds seems to work though.