<commit_before># encoding: utf-8
# Copyright © 2013 <NAME>. See LICENSE.txt for details.

if defined?(Delayed)

  CepaHealth.register :warn do
    priority = ENV['MAX_PRIORITY'] || 10
    now = Time.now.utc
    record "Delayed Job Backlog", true, Delayed::Job.count

    # Detect if the DJ backend is ActiveRecord or Mongoid Based
    type = case
    when Delayed::Job.respond_to?(:order_by) then :mongoid
    when Delayed::Job.respond_to?(:order) then :active_record
    else nil
    end

    # Maximum Delayed Job age is an hour
    unless type.nil?
      query = type == :active_record ? Delayed::Job.order("run_at DESC") : Delayed::Job.order_by(:run_at.desc)
      value = query.last
      if value.nil? || value.run_at > now
        record 'Delayed Job Backlog Age', true, 'No expired jobs'
      else
        diff = (now - value.run_at)
        record 'Delayed Job Backlog Age', diff < 3600, "#{'%.1f' % (diff/60)} mins"
      end
    end

    # Check for failed jobs
    if type.nil?
      [ "Unknown Delayed Job Backend", false, "#{Delayed::Job}" ]
    else
      failures = if type == :active_record 
        Delayed::Job.where("attempts > 0 AND priority < #{priority}").count 
      else
        Delayed::Job.where(:attempts.gt => 0, :priority.lt => priority).count
      end
      ["Delayed Job Failures", failures == 0, "#{failures} failed job#{failures == 1 ? '' : 's'}"]
    end
  end

end<commit_msg>added 'low priority failures' - that don't 'alarm'<commit_after># encoding: utf-8
# Copyright © 2013 <NAME>. See LICENSE.txt for details.

if defined?(Delayed)

  CepaHealth.register :warn do
    priority = ENV['MAX_PRIORITY'] || 10
    now = Time.now.utc
    record "Delayed Job Backlog", true, Delayed::Job.count

    # Detect if the DJ backend is ActiveRecord or Mongoid Based
    type = case
    when Delayed::Job.respond_to?(:order_by) then :mongoid
    when Delayed::Job.respond_to?(:order) then :active_record
    else nil
    end

    # Maximum Delayed Job age is an hour
    unless type.nil?
      query = type == :active_record ? Delayed::Job.order("run_at DESC") : Delayed::Job.order_by(:run_at.desc)
      value = query.last
      if value.nil? || value.run_at > now
        record 'Delayed Job Backlog Age', true, 'No expired jobs'
      else
        diff = (now - value.run_at)
        record 'Delayed Job Backlog Age', diff < 3600, "#{'%.1f' % (diff/60)} mins"
      end
    end

    # Check for failed jobs
    if type.nil?
      [ "Unknown Delayed Job Backend", false, "#{Delayed::Job}" ]
    else

      failures = if type == :active_record 
        Delayed::Job.where("attempts > 0 AND priority < #{priority}").count 
      else
        Delayed::Job.where(:attempts.gt => 0, :priority.lt => priority).count
      end
      record "Delayed Job High Priority", failures == 0, "#{failures} failed job#{failures == 1 ? '' : 's'}"

      low_priority_failures = if type == :active_record 
        Delayed::Job.where("attempts > 0 AND priority >= #{priority}").count 
      else
        Delayed::Job.where(:attempts.gt => 0, :priority.gte => priority).count
      end
      ['Delayed Job Low Priority', true, "#{low_priority_failures} failed low priority job#{low_priority_failures == 1 ? '' : 's'}"]
    end
  end

end
{'fraction_non_alphanumeric': 0.13212195873113644, 'fraction_numerical': 0.01201108715737604, 'mean_word_length': 2.857482185273159, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, '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': '6848490', 'n_tokens_mistral': 1105, 'n_tokens_neox': 1030, 'n_words': 308}