1module RateLimiting |
|
2 extend ActiveSupport::Concern |
|
4 included do |
|
5 rescue_from(ActiveJob::DeserializationError) do |exception| |
|
6 Appsignal.send_exception exception |
|
7 end |
|
8 end |
|
|
10 def perform(signature) |
11 if rate_limit.exceeded?(signature) |
|
12 signature.fraudulent!
|
|
13 end |
|
15 mailer.send(email, signature).deliver_now
|
|
17 updates, params = [], {}
|
|
18 updates << "email_count = COALESCE(email_count, 0) + 1" |
|
|
20 if constituency = signature.constituency |
21 updates << "constituency_id = :constituency_id" |
|
22 params[:constituency_id] = constituency.external_id |
|
23 end |
|
25 signature.update_all([updates.join(", "), params]) |
|
26 end |
|
28 private
|
|
|
30 def rate_limit |
31 @rate_limit ||= RateLimit.first_or_create! |
|
32 end |
|
33end |