<commit_before>require 'fileutils'

module QueueManager
  class Daemon
    class << self

      def start
        if running?
          puts 'Queue manager is already running. Use: QueueManager::Daemon.stop'
          return false
        end

        fork do
          $running = true
          File.write(QueueManager.config.pid_file, Process.pid)
          puts 'Queue manager is running...'

          Signal.trap('TERM') { $running = false }
          while $running do
            QueueManager::Task.handling_queue
            sleep(QueueManager.config.wait)
          end
        end
      ensure
        exit!(1)
      end

      def stop
        unless running?
          puts 'Queue manager is not running. Use: QueueManager::Daemon.start'
          return false
        end

        Process.kill('TERM', File.read(QueueManager.config.pid_file).to_i)
        FileUtils.rm_rf(QueueManager.config.pid_file)
        true
      rescue
        false
      end

      private

      def running?
        File.exist? QueueManager.config.pid_file
      end

    end
  end
end<commit_msg>Update daemon<commit_after>require 'fileutils'

module QueueManager
  class Daemon
    class << self
      def start
        if running?
          puts 'Queue manager is already running. To stop it, use rake queue_manager:stop'
          return false
        end

        fork do
          $running = true
          File.write(pid_file, Process.pid)
          puts 'Queue manager is running...'

          Signal.trap('TERM') do
            $running = false
            remove_pid_file
          end

          while $running do
            QueueManager::Task.handling_queue
            sleep config.wait
          end
        end
      ensure
        exit!(1)
      end

      def stop
        unless running?
          puts 'Queue manager is not running. To start it, use: rake queue_manager:start'
          return false
        end

        Process.kill('TERM', File.read(pid_file).to_i)
        remove_pid_file
        true
      rescue
        false
      end

      private

      def running?
        File.exist? pid_file
      end

      def remove_pid_file
        FileUtils.rm_rf(pid_file)
      end

      def pid_file
        config.pid_file
      end

      def config
        QueueManager.config
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.0618822518263859, 'fraction_numerical': 0.0008594757198109154, 'mean_word_length': 1.5387131952017448, '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': '4122261', 'n_tokens_mistral': 649, 'n_tokens_neox': 631, 'n_words': 180}