Updated

app/jobs / archive_signatures_job.rb

C
74 lines of codes
2 methods
55.9 complexity/method
8 churn
111.75 complexity
0 duplications
class ArchiveSignaturesJob < ApplicationJob
  1. ArchiveSignaturesJob has no descriptive comment
queue_as :low_priority def perform(petition, archived_petition, limit: 1000)
  1. ArchiveSignaturesJob#perform has a flog score of 105
  2. ArchiveSignaturesJob#perform has approx 39 statements
terminating = false worker = trap("TERM") do terminating = true worker.call end Appsignal.without_instrumentation do if petition.signatures.unarchived.exists?
  1. ArchiveSignaturesJob#perform calls 'petition.signatures' 3 times Locations: 0 1 2
  2. ArchiveSignaturesJob#perform calls 'petition.signatures.unarchived' 3 times Locations: 0 1 2
  3. ArchiveSignaturesJob#perform calls 'petition.signatures.unarchived.exists?' 2 times Locations: 0 1
signatures = petition.signatures.unarchived.batch(limit: limit)
  1. ArchiveSignaturesJob#perform calls 'petition.signatures' 3 times Locations: 0 1 2
  2. ArchiveSignaturesJob#perform calls 'petition.signatures.unarchived' 3 times Locations: 0 1 2
signatures.each do |signature| signature.with_lock do
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
unless signature.archived_at?
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
archived_signature = Archived::Signature.new do |s|
  1. ArchiveSignaturesJob#perform contains iterators nested 2 deep
  2. ArchiveSignaturesJob#perform has the variable name 's'
s.petition_id = signature.petition_id
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
s.uuid = signature.uuid
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
s.state = signature.state
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
s.number = signature.number
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
s.name = signature.name
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
s.email = signature.email
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
s.postcode = signature.postcode
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
s.location_code = signature.location_code
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
s.constituency_id = signature.constituency_id
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
s.ip_address = signature.ip_address
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
s.perishable_token = signature.perishable_token
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
s.unsubscribe_token = signature.unsubscribe_token
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
s.notify_by_email = signature.notify_by_email
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
s.validated_at = signature.validated_at
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
s.invalidation_id = signature.invalidation_id
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
s.invalidated_at = signature.invalidated_at
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
s.government_response_email_at = signature.government_response_email_at
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
s.debate_scheduled_email_at = signature.debate_scheduled_email_at
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
s.debate_outcome_email_at = signature.debate_outcome_email_at
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
s.petition_email_at = signature.petition_email_at
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
s.creator = signature.creator?
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
s.sponsor = signature.sponsor?
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
s.created_at = signature.created_at
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
s.updated_at = signature.updated_at
  1. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
end archived_signature.save!(validate: false) signature.update_column(:archived_at, Time.current)
  1. ArchiveSignaturesJob#perform calls 'Time.current' 2 times Locations: 0 1
  2. ArchiveSignaturesJob#perform refers to 'signature' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
end end if terminating reschedule_job(petition, archived_petition, limit: limit) return true end end end end if petition.signatures.unarchived.exists?
  1. ArchiveSignaturesJob#perform calls 'petition.signatures' 3 times Locations: 0 1 2
  2. ArchiveSignaturesJob#perform calls 'petition.signatures.unarchived' 3 times Locations: 0 1 2
  3. ArchiveSignaturesJob#perform calls 'petition.signatures.unarchived.exists?' 2 times Locations: 0 1
self.class.perform_later(petition, archived_petition, limit: limit) else petition.update_column(:archived_at, Time.current)
  1. ArchiveSignaturesJob#perform calls 'Time.current' 2 times Locations: 0 1
end ensure trap "TERM", worker end private def reschedule_job(petition, archived_petition, limit: 1000, wait_until: 5.minutes.from_now)
  1. ArchiveSignaturesJob#reschedule_job has 4 parameters
  2. ArchiveSignaturesJob#reschedule_job has unused parameter 'limit'
self.class.set(wait_until: wait_until).perform_later(petition, archived_petition) end end