<commit_before>class TimeoutWorker < BaseWorker
  class Error < ::StandardError; end
  class TimeOutNotSetError < Error; end

  include Sidekiq::Worker

  def self.start_timeout_clock(ontology_version_id, start_time=nil)
    start_time ||= self.time_since_epoch
    self.perform_async(start_time, ontology_version_id)
  end

  def self.time_since_epoch(time=Time.now)
    time.strftime('%s').to_i
  end

  def perform(start_time, ontology_version_id)
    if timeout_reached?(Time.at(start_time))
      version = OntologyVersion.find(ontology_version_id)
      version.update_state!('failed', "The job reached the timeout limit of #{timeout_limit} hours.")
    end
  end

  def timeout_limit
    raise TimeOutNotSetError unless Settings.ontology_parse_timeout
    Settings.ontology_parse_timeout
  end

  def timeout_reached?(start_time)
    one_hour = 3600
    timeout_time = start_time + timeout_limit * one_hour
    Time.now >= timeout_time
  end

end
<commit_msg>adjust timeout worker for rescheduling<commit_after>class TimeoutWorker < BaseWorker
  class Error < ::StandardError; end
  class TimeOutNotSetError < Error; end

  RESCHEDULE_TIME = 30 # minutes

  include Sidekiq::Worker

  def self.start_timeout_clock(ontology_version_id, hours_offset=nil)
    hours_offset ||= Settings.ontology_parse_timeout
    self.perform_in(hours_offset.hours,
                    self.time_since_epoch, ontology_version_id)
  end

  def self.time_since_epoch(time=Time.now)
    time.strftime('%s').to_i
  end

  def perform(start_time, ontology_version_id)
    if timeout_reached?(Time.at(start_time))
      version = OntologyVersion.find(ontology_version_id)
      if state_not_terminal?(version)
        version.update_state!('failed', "The job reached the timeout limit of #{timeout_limit} hours.")
      end
    else
      self.class.perform_in(RESCHEDULE_TIME.minutes, start_time, ontology_version_id)
    end
  end

  def state_not_terminal?(ontology_version)
    !(ontology_version.state == 'failed' || ontology_version.state == 'done')
  end

  def timeout_limit
    raise TimeOutNotSetError unless Settings.ontology_parse_timeout
    Settings.ontology_parse_timeout
  end

  def timeout_reached?(start_time)
    one_hour = 3600
    timeout_time = start_time + timeout_limit * one_hour
    Time.now >= timeout_time
  end

end

{'fraction_non_alphanumeric': 0.07864202836269875, 'fraction_numerical': 0.004297378599054577, 'mean_word_length': 4.327231121281464, 'pattern_counts': {'":': 0, '<': 9, '<?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': '4853807', 'n_tokens_mistral': 766, 'n_tokens_neox': 741, 'n_words': 150}