<commit_before>module TaskVault

  class Component < BBLib::LazyClass
    attr_of Object, :parent, allow_nil: true
    attr_array_of Symbol, :handlers, raise: true, serialize: true, always: true
    attr_int_between 0, nil, :history_limit, default: 100, serialize: true, always: true
    attr_int_between 0, nil, :message_limit, default: 100000, serialize: true, always: true
    attr_reader :message_queue, :thread, :started, :stopped, :history

    def start
      init_thread unless running?
      @started = Time.now
      running?
    end

    def stop
      @stopped = Time.now if running?
      @thread.kill if @thread
      sleep(0.2)
      !running?
    end

    def restart
      stop && start
    end

    def running?
      !@thread.nil? && @thread.alive?
    end

    def uptime
      return 0 if @started.nil?
      running? ? Time.now - @started : 0
    end

    def queue_msg msg, **data
      msg = {
          msg: msg,
          handlers: @handlers
        }.merge(compile_msg_data(**data))
      @history.unshift(msg.dup)<commit_msg>Added default severity detection for messages.<commit_after>module TaskVault

  class Component < BBLib::LazyClass
    attr_of Object, :parent, allow_nil: true
    attr_array_of Symbol, :handlers, raise: true, serialize: true, always: true
    attr_int_between 0, nil, :history_limit, default: 100, serialize: true, always: true
    attr_int_between 0, nil, :message_limit, default: 100000, serialize: true, always: true
    attr_reader :message_queue, :thread, :started, :stopped, :history

    def start
      init_thread unless running?
      @started = Time.now
      running?
    end

    def stop
      @stopped = Time.now if running?
      @thread.kill if @thread
      sleep(0.2)
      !running?
    end

    def restart
      stop && start
    end

    def running?
      !@thread.nil? && @thread.alive?
    end

    def uptime
      return 0 if @started.nil?
      running? ? Time.now - @started : 0
    end

    def queue_msg msg, **data
      msg = {
          msg:      msg,
          handlers: @handlers,
          severity: (msg.is_a?(Exception) ? :error : :info)
        }.merge(compile_msg_data(**data))
      @history.unshift(msg.dup)
{'fraction_non_alphanumeric': 0.10113378684807256, 'fraction_numerical': 0.013605442176870748, 'mean_word_length': 2.5296, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4502342', 'n_tokens_mistral': 744, 'n_tokens_neox': 688, 'n_words': 204}