Updated

app/jobs / trending_domains_by_petition_job.rb

C
56 lines of codes
7 methods
5.2 complexity/method
1 churn
36.48 complexity
56 duplications
class TrendingDomainsByPetitionJob < ApplicationJob
  1. TrendingDomainsByPetitionJob has no descriptive comment
delegate :enable_logging_of_trending_items?, to: :rate_limit delegate :threshold_for_logging_trending_items, to: :rate_limit delegate :threshold_for_notifying_trending_items, to: :rate_limit delegate :ignore_domain?, to: :rate_limit delegate :trending_domains_by_petition, to: :Signature def perform(now = Time.current)
  1. Similar code found in 2 nodes Locations: 0 1
  2. TrendingDomainsByPetitionJob#perform has approx 10 statements
return unless enable_logging_of_trending_items? trending_domains(now).each do |id, domains| petition = Petition.find(id) domains.each do |domain, count|
  1. TrendingDomainsByPetitionJob#perform contains iterators nested 2 deep
next unless domain.present? next if ignore_domain?(domain) begin trending_domain = petition.trending_domains.log!(starts_at(now), domain, count) if count >= threshold_for_notifying_trending_items NotifyTrendingDomainJob.perform_later(trending_domain) end rescue StandardError => e
  1. TrendingDomainsByPetitionJob#perform has the variable name 'e'
Appsignal.send_exception e end end end end private def rate_limit @rate_limit ||= RateLimit.first_or_create! end def trending_domains(now) trending_domains_by_petition(window(now), threshold_for_logging_trending_items) end def petitions Petition.where(id: petition_ids) end def window(now) starts_at(now)..ends_at(now) end def starts_at(now) @starts_at ||= ends_at(now).advance(hours: -1) end def ends_at(now) @ends_at ||= now.at_beginning_of_hour end end