Updated

app/jobs / backfill_constituencies_job.rb

A
33 lines of codes
3 methods
8.5 complexity/method
1 churn
25.63 complexity
0 duplications
class BackfillConstituenciesJob < ApplicationJob
  1. BackfillConstituenciesJob has no descriptive comment
queue_as :low_priority def perform(id: 0, since: nil)
  1. BackfillConstituenciesJob takes parameters ['id', 'since'] to 3 methods Locations: 0 1 2
  2. BackfillConstituenciesJob#perform has approx 8 statements
return if Site.disable_constituency_api? since = since.try(:in_time_zone) signatures = signatures_missing_constituency_id(id, since).to_a max_id = signatures.map(&:id).max signatures.each do |signature| next if signature.constituency_id? if constituency = signature.constituency signature.update_column(:constituency_id, constituency.external_id) end end if reschedule?(max_id, since) self.class.perform_later(id: max_id, since: since.try(:iso8601)) end end private def signatures_missing_constituency_id(id, since)
  1. BackfillConstituenciesJob takes parameters ['id', 'since'] to 3 methods Locations: 0 1 2
  2. BackfillConstituenciesJob#signatures_missing_constituency_id doesn't depend on instance state (maybe move it to another class?)
Signature.missing_constituency_id(since: since).batch(id) end def reschedule?(id, since)
  1. BackfillConstituenciesJob takes parameters ['id', 'since'] to 3 methods Locations: 0 1 2
signatures_missing_constituency_id(id, since).exists? end end