|
1class TrendingIpsByPetitionJob < ApplicationJob
|
|
2 delegate :enable_logging_of_trending_items?, to: :rate_limit
|
|
3 delegate :threshold_for_logging_trending_items, to: :rate_limit
|
|
4 delegate :threshold_for_notifying_trending_items, to: :rate_limit
|
|
5 delegate :ignore_ip?, to: :rate_limit
|
|
6 delegate :ignored_domains_list, to: :rate_limit
|
|
7 delegate :trending_ips_by_petition, to: :Signature
|
|
|
- NestedIterators - contains iterators nested 2 deep » reek
- TooManyStatements - has approx 10 statements » reek
- UncommunicativeVariableName - has the variable name 'e' » reek
- Complexity 8 » saikuro
|
9 def perform(now = Time.current)
|
|
10 return unless enable_logging_of_trending_items?
|
|
|
- Block cyclomatic complexity is 5. It should be 4 or less. » roodi
|
12 trending_ips(now).each do |id, ips|
|
|
13 petition = Petition.find(id)
|
|
|
|
15 ips.each do |ip, count|
|
|
16 next unless ip.present?
|
|
17 next if ignore_ip?(ip)
|
|
|
|
|
|
20 trending_ip = petition.trending_ips.log!(starts_at(now), ip, count)
|
|
|
|
22 if count >= threshold_for_notifying_trending_items
|
|
23 NotifyTrendingIpJob.perform_later(trending_ip)
|
|
|
|
25 rescue StandardError => e
|
|
26 Appsignal.send_exception e
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 @rate_limit ||= RateLimit.first_or_create!
|
|
|
|
|
|
|
|
39 trending_ips_by_petition(window(now), threshold_for_logging_trending_items, ignored_domains_list)
|
|
|
|
|
|
|
|
43 Petition.where(id: petition_ids)
|
|
|
|
|
|
|
|
47 starts_at(now)..ends_at(now)
|
|
|
|
|
|
|
|
51 @starts_at ||= ends_at(now).advance(hours: -1)
|
|
|
|
|
|
|
|
55 @ends_at ||= now.at_beginning_of_hour
|
|
|
|
|