|
1class TrendingDomainsByPetitionJob < 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_domain?, to: :rate_limit
|
|
6 delegate :trending_domains_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
|
8 def perform(now = Time.current)
|
|
9 return unless enable_logging_of_trending_items?
|
|
|
- Block cyclomatic complexity is 5. It should be 4 or less. » roodi
|
11 trending_domains(now).each do |id, domains|
|
|
12 petition = Petition.find(id)
|
|
|
|
14 domains.each do |domain, count|
|
|
15 next unless domain.present?
|
|
16 next if ignore_domain?(domain)
|
|
|
|
|
|
19 trending_domain = petition.trending_domains.log!(starts_at(now), domain, count)
|
|
|
|
21 if count >= threshold_for_notifying_trending_items
|
|
22 NotifyTrendingDomainJob.perform_later(trending_domain)
|
|
|
|
24 rescue StandardError => e
|
|
25 Appsignal.send_exception e
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 @rate_limit ||= RateLimit.first_or_create!
|
|
|
|
|
|
37 def trending_domains(now)
|
|
38 trending_domains_by_petition(window(now), threshold_for_logging_trending_items)
|
|
|
|
|
|
|
|
42 Petition.where(id: petition_ids)
|
|
|
|
|
|
|
|
46 starts_at(now)..ends_at(now)
|
|
|
|
|
|
|
|
50 @starts_at ||= ends_at(now).advance(hours: -1)
|
|
|
|
|
|
|
|
54 @ends_at ||= now.at_beginning_of_hour
|
|
|
|
|