1class BackfillConstituenciesJob < ApplicationJob
 
2  queue_as :low_priority
 
3
  • TooManyStatements - has approx 8 statements » reek
  • Complexity 6 » saikuro
4  def perform(id: 0, since: nil)
 
5    return if Site.disable_constituency_api?
 
6
 
7    since = since.try(:in_time_zone)
 
8    signatures = signatures_missing_constituency_id(id, since).to_a
 
 9    max_id = signatures.map(&:id).max
 
 
11    signatures.each do |signature|
 
12      next if signature.constituency_id?
 
  • Found = in conditional. It should probably be an == » roodi
14      if constituency = signature.constituency
 
15        signature.update_column(:constituency_id, constituency.external_id)
 
16      end
 
17    end
 
 
19    if reschedule?(max_id, since)
 
20      self.class.perform_later(id: max_id, since: since.try(:iso8601))
 
21    end
 
22  end
 
 
24  private
 
  • UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
  • Complexity 1 » saikuro
26  def signatures_missing_constituency_id(id, since)
 
27    Signature.missing_constituency_id(since: since).batch(id)
 
28  end
 
  • Complexity 1 » saikuro
30  def reschedule?(id, since)
 
31    signatures_missing_constituency_id(id, since).exists?
 
32  end
 
33end