<commit_before>module Workerholic
  class JobProcessor
    attr_reader :serialized_job

    def initialize(serialized_job)
      @serialized_job = serialized_job
      @logger = LogManager.new
    end

    def process
      job = JobSerializer.deserialize(serialized_job)

      begin
        job.statistics.started_at = Time.now.to_f
        job_result = job.perform
        job.statistics.completed_at = Time.now.to_f

        StatsStorage.save_job('completed_jobs', job)

        # @logger.info("Completed: your job from class #{job.klass} was completed on #{job.statistics.completed_at}.")
      rescue Exception => e
        job.statistics.errors.push([e.class, e.message])
        retry_job(job)

      end
      job_result
    end

    private

    def retry_job(job)
      unless JobRetry.new(job: job).retry
        job.statistics.failed_on = Time.now.to_f
        StatsStorage.save_job('failed_jobs', job)
        # @logger.error("Failed: your job from class #{job.class} was unsuccessful.")
      else
        # @logger.error("Failed: your job from class #{job.class} was unsuccessful. Retrying in 10 secs...")
      end
    end
  end
end<commit_msg>refactor retry_job into more readable code<commit_after>module Workerholic
  class JobProcessor
    attr_reader :serialized_job

    def initialize(serialized_job)
      @serialized_job = serialized_job
      @logger = LogManager.new
    end

    def process
      job = JobSerializer.deserialize(serialized_job)

      begin
        job.statistics.started_at = Time.now.to_f
        job_result = job.perform
        job.statistics.completed_at = Time.now.to_f

        StatsStorage.save_job('completed_jobs', job)

        # @logger.info("Completed: your job from class #{job.klass} was completed on #{job.statistics.completed_at}.")
      rescue Exception => e
        job.statistics.errors.push([e.class, e.message])
        retry_job(job)

      end
      job_result
    end

    private

    def retry_job(job)
      if JobRetry.new(job: job).retry
        # @logger.error("Failed: your job from class #{job.class} was unsuccessful. Retrying in 10 secs...")
      else
        job.statistics.failed_on = Time.now.to_f
        StatsStorage.save_job('failed_jobs', job)

        # @logger.error("Failed: your job from class #{job.class} was unsuccessful.")
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09540034071550256, 'fraction_numerical': 0.0017035775127768314, 'mean_word_length': 2.6306027820710973, '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': '950172', 'n_tokens_mistral': 737, 'n_tokens_neox': 708, 'n_words': 164}