<commit_before>module Crono
  class Job
    include Logging

    attr_accessor :performer
    attr_accessor :period
    attr_accessor :last_performed_at

    def initialize(performer, period)
      self.performer, self.period = performer, period
    end

    def next
      period.next(since: last_performed_at)
    end

    def description
      "Perform #{performer} #{period.description}"
    end

    def job_id
      description
    end

    def perform
      logger.info "Perform #{performer}"
      self.last_performed_at = Time.now
      save
      Thread.new do
        performer.new.perform
        logger.info "Finished #{performer} in %.2f seconds" % (Time.now - last_performed_at)
      end
    end

    def save
      model.update(last_performed_at: last_performed_at)
    end

    def load
      self.last_performed_at = model.last_performed_at<commit_msg>Handle situation when Job#next is in the past<commit_after>module Crono
  class Job
    include Logging

    attr_accessor :performer
    attr_accessor :period
    attr_accessor :last_performed_at

    def initialize(performer, period)
      self.performer, self.period = performer, period
    end

    def next
      next_time = period.next(since: last_performed_at)
      next_time.past? ? period.next : next_time
    end

    def description
      "Perform #{performer} #{period.description}"
    end

    def job_id
      description
    end

    def perform
      logger.info "Perform #{performer}"
      self.last_performed_at = Time.now
      save
      Thread.new do
        performer.new.perform
        logger.info "Finished #{performer} in %.2f seconds" % (Time.now - last_performed_at)
      end
    end

    def save
      model.update(last_performed_at: last_performed_at)
    end

    def load
      self.last_performed_at = model.last_performed_at
{'fraction_non_alphanumeric': 0.06815703380588876, 'fraction_numerical': 0.0010905125408942203, 'mean_word_length': 2.563106796116505, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4365906', 'n_tokens_mistral': 583, 'n_tokens_neox': 561, 'n_words': 140}