<commit_before>require_relative 'task_queue'

class TaskVault

  class Vault < Component
    attr_reader :queue, :limit, :last_id, :elevation_policy, :interval

    def limit= l
      @limit = l.nil? ? nil : BBLib::keep_between(l, 0, nil)
    end

    def interval= i
      @interval = i.nil? ? nil : BBLib.keep_between(i, 0, nil)
    end

    def method_missing *args, **named
      if @queue.respond_to?(args.first)
        if named.empty?
          @queue.send(args.first, *args[1..-1])
        else
          @queue.send(args.first, *args[1..-1], **named)
        end
      else
        raise ArgumentError, "Missing method for '#{args.first}' in #{self.class}"
      end
    end

    protected

      def setup_defaults
        @queue = TaskQueue.new
        @elevation_policy = { 0 => nil, 1 => 60, 2 => 30, 3 => 30, 4 => 60, 5 => 120, 6 => nil }
        @last_id, @interval, @limit = 0, 0.2, 5
      end

      def init_thread
        # [:sort, :ready_up, [:elevate_tasks, @elevation_policy], :sort, :check_running, [:run_tasks, @limit], :clear].each do |method|
        #   @queue.send(*method).to_a.each{ |m| queue_msg(m)}
        # end
        @thread = Thread.new {
          begin
            loop do
              start = Time.now.to_f

              [:sort, :ready_up, [:elevate_tasks, @elevation_policy], :sort, :check_running, [:run_tasks, @limit], :clean].each do |method|
                @queue.send(*method).to_a.each{ |m| queue_msg(m)}
              end

              sleep_time = @interval - (Time.now.to_f - start)<commit_msg>Mostly minor tweaks. Moved ids to TaskQueue<commit_after>require_relative 'task_queue'

class TaskVault

  class Vault < Component
    attr_reader :queue, :limit, :elevation_policy, :interval, :path

    def limit= l
      @limit = l.nil? ? nil : BBLib::keep_between(l, 0, nil)
    end

    def path= p
      @path = p.to_s.gsub('\\', '/')
    end

    def interval= i
      @interval = i.nil? ? nil : BBLib.keep_between(i, 0, nil)
    end

    def queue task
      @queue.queue task
    end

    def method_missing *args, **named
      if @queue.respond_to?(args.first)
        if named.empty?
          @queue.send(args.first, *args[1..-1])
        else
          @queue.send(args.first, *args[1..-1], **named)
        end
      else
        raise NoMethodError, "Missing method for '#{args.first}' in #{self.class}"
      end
    end

    protected

      def setup_defaults
        @queue = TaskQueue.new
        @elevation_policy = { 0 => nil, 1 => 60, 2 => 30, 3 => 30, 4 => 60, 5 => 120, 6 => nil }
        @interval, @limit = 0.2, 5
      end

      def init_thread
        # [:sort, :ready_up, [:elevate_tasks, @elevation_policy], :sort, :check_running, [:run_tasks, @limit], :clear].each do |method|
        #   @queue.send(*method).to_a.each{ |m| queue_msg(m)}
        # end
        @thread = Thread.new {
          begin
            loop do
              start = Time.now.to_f

              [:sort, :ready_up, [:elevate_tasks, @elevation_policy], :sort, :check_running, [:run_tasks, @limit], :clean].each do |method|
                @queue.send(*method).to_a.each{ |m| queue_msg(m)}
              end

              sleep_time = @interval - (Time.now.to_f - start)
{'fraction_non_alphanumeric': 0.143521388716677, 'fraction_numerical': 0.017048977061376317, 'mean_word_length': 2.133009708737864, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2242138', 'n_tokens_mistral': 1165, 'n_tokens_neox': 1084, 'n_words': 273}