<commit_before>module WatchmonkeyCli
  class Checker
    # Descendant tracking for inherited classes.
    def self.descendants
      @descendants ||= []
    end

    def self.inherited(descendant)
      descendants << descendant
    end

    def self.checker_name
      @checker_name || self.name
    end

    def self.checker_name= name
      @checker_name = name
    end

    def self.maxrt
      @maxrt
    end

    def self.maxrt= seconds
      @maxrt = seconds
    end

    module AppHelper
      def init_checkers!
        @checkers = {}
        WatchmonkeyCli::Checker.descendants.uniq.each do |klass|
          debug "[SETUP] Initializing checker `#{klass.name}'"
          @checkers[klass.checker_name] = klass.new(self)
        end
      end

      def start_checkers!
        @checkers.each do |key, instance|
          debug "[SETUP] Starting checker `#{key}' (#{instance.class.name})"
          instance.start
        end
      end

      def stop_checkers!
        return unless @checkers
        @checkers.each do |key, instance|
          debug "[SETUP] Stopping checker `#{key}' (#{instance.class.name})"
          instance.stop
        end
      end
    end

    class Result
      attr_reader :checker, :type, :args
      attr_accessor :result, :command, :data

      def initialize checker, *args
        @checker = checker
        @args = args
        @mutex = Monitor.new
        @type = :info
        @spool = { error: [], info: [], debug: []}
      end

      def sync &block
        @mutex.synchronize(&block)
      end

      def descriptor
        "[#{@checker.class.checker_name} | #{args.join(" | ")}]"
      end

      def str_safe
        "#{descriptor}\n\t"
      end

      def str_running
        "Running checker #{@checker.class.checker_name} with [#{args.join(" | ")}]"
      end

      def str_descriptor
        "#{descriptor}\n\t"
      end

      def messages<commit_msg>Add a uniqid method to checkers (for throttling)<commit_after>module WatchmonkeyCli
  class Checker
    # Descendant tracking for inherited classes.
    def self.descendants
      @descendants ||= []
    end

    def self.inherited(descendant)
      descendants << descendant
    end

    def self.checker_name
      @checker_name || self.name
    end

    def self.checker_name= name
      @checker_name = name
    end

    def self.maxrt
      @maxrt
    end

    def self.maxrt= seconds
      @maxrt = seconds
    end

    module AppHelper
      def init_checkers!
        @checkers = {}
        WatchmonkeyCli::Checker.descendants.uniq.each do |klass|
          debug "[SETUP] Initializing checker `#{klass.name}'"
          @checkers[klass.checker_name] = klass.new(self)
        end
      end

      def start_checkers!
        @checkers.each do |key, instance|
          debug "[SETUP] Starting checker `#{key}' (#{instance.class.name})"
          instance.start
        end
      end

      def stop_checkers!
        return unless @checkers
        @checkers.each do |key, instance|
          debug "[SETUP] Stopping checker `#{key}' (#{instance.class.name})"
          instance.stop
        end
      end
    end

    class Result
      attr_reader :checker, :type, :args
      attr_accessor :result, :command, :data

      def initialize checker, *args
        @checker = checker
        @args = args
        @mutex = Monitor.new
        @type = :info
        @spool = { error: [], info: [], debug: []}
      end

      def uniqid additional = []
        ([
          self.class.name,
          @args.map(&:to_s).to_s,
        ] + additional).join("/")
      end

      def sync &block
        @mutex.synchronize(&block)
      end

      def descriptor
        "[#{@checker.class.checker_name} | #{args.join(" | ")}]"
      end

      def str_safe
        "#{descriptor}\n\t"
      end

      def str_running
        "Running checker #{@checker.class.checker_name} with [#{args.join(" | ")}]"
      end

      def str_descriptor
        "#{descriptor}\n\t"
      end

      def messages
{'fraction_non_alphanumeric': 0.10900473933649289, 'fraction_numerical': 0.0, 'mean_word_length': 1.9163636363636363, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '4015348', 'n_tokens_mistral': 1259, 'n_tokens_neox': 1232, 'n_words': 303}