<commit_before>module TrackableTasks
  # Abstract trackable task to be overriden when creating a trackable task.
  #
  # Usage:
  #
  # Create a class
  # MyGenericTask < TrackableTasks:Base
  #
  # Override the run method
  # def run
  #   puts "Running my own code"
  # end
  #
  # Instantiate and call run_task
  #
  # my_generic_task = MyGenericTask.new
  # my_generic_task.run_task
  #
  # Bask in the glory of your saved logging information
  #
  # puts TrackableTasks.TaskRun.last.log_text
  class Base

    # Initializes the task run and sets the start time
    #
    # @param [Symbol] log_level The log level for the task, defaults to notice
    def initialize(log_level = :notice)
      @task_run = TrackableTasks::TaskRun.create(:start_time => Time.now, :task_type => self.class.name, :success => true)

      @log_levels = [:debug, :notice, :error]
      @log_level = allowable_log_level(log_level)
    end

    # Checks if the log level is an allowable level, then returns it or notice if it is not allowable
    #
    # @param [Sybmol] log_level Log level to check
    # @return [Symbol] The given log level or notice if it is not allowable
    def allowable_log_level(log_level) 
      log_level = "" if log_level.nil?
      log_level = log_level.to_sym unless log_level.is_a?(Symbol)
      if !@log_levels.include?(log_level)
        log_level = :notice
      end
      return log_level
    end

    # this calls task with error catching
    # if an error is caught, sets success to false and records the error
    # either way, sets an end time and saves the task run information
    def run_task
      begin
        run 
      rescue Exception => e
        @task_run.add_error_text(e.class.name + ": " + e.message)
        @task_run.success = false
      end 
      @task_run.end_time = Time.now<commit_msg>Added a backtrace to the error log when an exception is raised.<commit_after>module TrackableTasks
  # Abstract trackable task to be overriden when creating a trackable task.
  #
  # Usage:
  #
  # Create a class
  # MyGenericTask < TrackableTasks:Base
  #
  # Override the run method
  # def run
  #   puts "Running my own code"
  # end
  #
  # Instantiate and call run_task
  #
  # my_generic_task = MyGenericTask.new
  # my_generic_task.run_task
  #
  # Bask in the glory of your saved logging information
  #
  # puts TrackableTasks.TaskRun.last.log_text
  class Base

    # Initializes the task run and sets the start time
    #
    # @param [Symbol] log_level The log level for the task, defaults to notice
    def initialize(log_level = :notice)
      @task_run = TrackableTasks::TaskRun.create(:start_time => Time.now, :task_type => self.class.name, :success => true)

      @log_levels = [:debug, :notice, :error]
      @log_level = allowable_log_level(log_level)
    end

    # Checks if the log level is an allowable level, then returns it or notice if it is not allowable
    #
    # @param [Sybmol] log_level Log level to check
    # @return [Symbol] The given log level or notice if it is not allowable
    def allowable_log_level(log_level) 
      log_level = "" if log_level.nil?
      log_level = log_level.to_sym unless log_level.is_a?(Symbol)
      if !@log_levels.include?(log_level)
        log_level = :notice
      end
      return log_level
    end

    # this calls task with error catching
    # if an error is caught, sets success to false and records the error
    # either way, sets an end time and saves the task run information
    def run_task
      begin
        run 
      rescue Exception => e
        @task_run.add_error_text(e.class.name + ": " + e.message)
        @task_run.add_error_text(e.backtrace.inspect)
        @task_run.success = false
      end 
      @task_run.end_time = Time.now
{'fraction_non_alphanumeric': 0.0753862546616942, 'fraction_numerical': 0.0, 'mean_word_length': 2.8512820512820514, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 11, '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': '3191735', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1171, 'n_words': 391}