1class BackfillCanonicalEmailsJob < ApplicationJob
 
2  queue_as :low_priority
 
3
  • FeatureEnvy - refers to 'signature' more than self (maybe move it to another class?) » reek
  • TooManyStatements - has approx 6 statements » reek
  • Complexity 5 » saikuro
4  def perform(id = 0)
 
5    signatures = Signature.where(canonical_email: nil).batch(id).to_a
 
6    max_id = signatures.map(&:id).max
 
7
 
8    signatures.each do |signature|
 
 9      next if signature.canonical_email?
 
 
11      if signature.email?
 
12        signature.update_canonical_email
 
13      end
 
14    end
 
 
16    if Signature.exists?(canonical_email: nil)
 
17      self.class.perform_later(max_id)
 
18    end
 
19  end
 
20end