demarches-normaliennes/app/services/concerns/mail_rate_limitable.rb

14 lines
292 B
Ruby
Raw Normal View History

module MailRateLimitable
extend ActiveSupport::Concern
included do
def initialize(rate_limiter: MailRateLimiter.new(limit: 200, window: 10.minutes))
@rate_limiter = rate_limiter
end
def safe_send_email(mail)
@rate_limiter.send_with_delay(mail)
end
end
end