Updated

app/jobs / stop_petitions_early_job.rb

A
35 lines of codes
3 methods
7.9 complexity/method
3 churn
23.58 complexity
0 duplications
class StopPetitionsEarlyJob < ApplicationJob
  1. StopPetitionsEarlyJob has no descriptive comment
queue_as :high_priority class << self def schedule_for(time) set(wait_until: time).perform_later(time.iso8601) end end def perform(time) time = time.in_time_zone cutoff_time = Parliament.notification_cutoff_at Petition.in_need_of_stopping.find_each do |petition| if petition.created_at >= cutoff_time
  1. StopPetitionsEarlyJob#perform refers to 'petition' more than self (maybe move it to another class?) Locations: 0 1
send_notification(petition) end petition.stop!(time)
  1. StopPetitionsEarlyJob#perform refers to 'petition' more than self (maybe move it to another class?) Locations: 0 1
end end private def send_notification(petition)
  1. StopPetitionsEarlyJob#send_notification doesn't depend on instance state (maybe move it to another class?)
unless petition.special_consideration? case petition.state when Petition::VALIDATED_STATE NotifyCreatorOfValidatedPetitionBeingStoppedJob.perform_later(petition.creator)
  1. StopPetitionsEarlyJob#send_notification calls 'petition.creator' 2 times Locations: 0 1
when Petition::SPONSORED_STATE NotifyCreatorOfSponsoredPetitionBeingStoppedJob.perform_later(petition.creator)
  1. StopPetitionsEarlyJob#send_notification calls 'petition.creator' 2 times Locations: 0 1
end end end end