1class StopPetitionsEarlyJob < ApplicationJob
 
2  queue_as :high_priority
 
3
 
4  class << self
 
5    def schedule_for(time)
 
6      set(wait_until: time).perform_later(time.iso8601)
 
7    end
 
8  end
 
 9
  • FeatureEnvy - refers to 'petition' more than self (maybe move it to another class?) » reek
  • Complexity 3 » saikuro
10  def perform(time)
 
11    time = time.in_time_zone
 
12    cutoff_time = Parliament.notification_cutoff_at
 
 
14    Petition.in_need_of_stopping.find_each do |petition|
 
15      if petition.created_at >= cutoff_time
 
16        send_notification(petition)
 
17      end
 
 
19      petition.stop!(time)
 
20    end
 
21  end
 
 
23  private
 
  • DuplicateMethodCall - calls 'petition.creator' 2 times » reek
  • UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
  • Complexity 4 » saikuro
25  def send_notification(petition)
 
26    unless petition.special_consideration?
  • Case statement is missing an else clause. » roodi
27      case petition.state
 
28      when Petition::VALIDATED_STATE
 
29        NotifyCreatorOfValidatedPetitionBeingStoppedJob.perform_later(petition.creator)
 
30      when Petition::SPONSORED_STATE
 
31        NotifyCreatorOfSponsoredPetitionBeingStoppedJob.perform_later(petition.creator)
 
32      end
 
33    end
 
34  end
 
35end