<commit_before>module Kryten::Runner
  attr_accessor :timer
  attr_reader :running, :started

  def initialize title=nil
    @name, @running, @started = title, false, false
  end

  def setup
    log "setting up"
    Signal.trap("INT", proc { stop_running })
    Signal.trap("TERM", proc { stop_running })
  end

  def start
    setup
    log "started"
    @started = true

    while started do
      sleep timer
      @running = true
      run
      @running = false
    end

    log "stopped"
    true
  rescue => e
    log :error, "error: #{e} - from: #{e.backtrace.first}"
    raise
  end

  def timer
    @timer || 4
  end

  # stop the loop
  def stop_running
    @started = false
    shutdown
  end

  def debug
    log "debugging"
    setup
    2.times do
      run
      sleep timer
    end
  end

  def log message
    puts [name, message].join(': ')
  end

  def name
    @name || self.class.to_s.gsub('::','-').downcase
  end

  def status
    log [started ? 'on and ' : 'off and ',
         running ? 'running' : 'sleeping'].join
    started
  end

  # hook methods
  def shutdown; nil; end

  def run; nil; end

end<commit_msg>add hook methods to runner<commit_after>module Kryten::Runner
  attr_accessor :timer
  attr_reader :running, :started

  def initialize title=nil
    @name, @running, @started = title, false, false
  end

  def setup
    log "setting up"
    Signal.trap("INT", proc { stop_running })
    Signal.trap("TERM", proc { stop_running })
  end

  def start
    before_setup
    setup
    after_setup

    log "started"
    @started = true

    while started do
      sleep timer
      @running = true
      before_run
      run
      after_run
      @running = false
    end

    log "stopped"
    true
  rescue => e
    log :error, "error: #{e} - from: #{e.backtrace.first}"
    raise
  end

  def timer
    @timer || 4
  end

  # stop the loop
  def stop_running
    @started = false
    shutdown
  end

  def debug
    log "debugging"
    setup
    2.times do
      run
      sleep timer
    end
  end

  def log message
    puts [name, message].join(': ')
  end

  def name
    @name || self.class.to_s.gsub('::','-').downcase
  end

  def status
    log [started ? 'on and ' : 'off and ',
         running ? 'running' : 'sleeping'].join
    started
  end

  # hook methods
  def before_setup; nil; end
  def after_setup; nil; end
  def before_run; nil; end
  def run; nil; end
  def after_run; nil; end
  def shutdown; nil; end

end
{'fraction_non_alphanumeric': 0.09955483609874545, 'fraction_numerical': 0.0016187778227438284, 'mean_word_length': 2.1896774193548385, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2840721', 'n_tokens_mistral': 861, 'n_tokens_neox': 818, 'n_words': 267}