<commit_before>class Notification < ActiveRecord::Base
  belongs_to :job
  has_many :deliveries, :dependent => :destroy, :order => "notified_at DESC"

  after_initialize :set_initial_state

  def self.from_api(options=nil)
    return [] if options.blank?

    options.split(',').collect do |value|
      value.strip!
      value.include?('@') ? EmailNotification.new(:value => value) : UrlNotification.new(:value => value)
    end
  end
  
  def notify!(*args)
    begin
      do_notify!(*args)
      state = Job::Success
    rescue => e
      state = Job::Failed
    end
    deliveries.create!(:state => state, :state_change => job.state_changes.last, :notified_at => Time.current)
    self
  end

  def name
    self.class.to_s.gsub('Notification', '')
  end
  
  def initial_state
    Job::Scheduled
  end
  
  private
    def set_initial_state
      self.state ||= Job::Scheduled<commit_msg>A notification should update its state<commit_after>class Notification < ActiveRecord::Base
  belongs_to :job
  has_many :deliveries, :dependent => :destroy, :order => "notified_at DESC"

  after_initialize :set_initial_state

  def self.from_api(options=nil)
    return [] if options.blank?

    options.split(',').collect do |value|
      value.strip!
      value.include?('@') ? EmailNotification.new(:value => value) : UrlNotification.new(:value => value)
    end
  end
  
  def notify!(*args)
    begin
      do_notify!(*args)
      update_attributes :state => Job::Success
    rescue => e
      update_attributes :state => Job::Failed
    end
    deliveries.create!(:state => state, :state_change => job.state_changes.last, :notified_at => Time.current)
    self
  end

  def name
    self.class.to_s.gsub('Notification', '')
  end
  
  def initial_state
    Job::Scheduled
  end
  
  private
    def set_initial_state
      self.state ||= Job::Scheduled
{'fraction_non_alphanumeric': 0.12291105121293801, 'fraction_numerical': 0.0, 'mean_word_length': 3.336448598130841, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3797535', 'n_tokens_mistral': 596, 'n_tokens_neox': 591, 'n_words': 130}