<commit_before>every '1s', :mutex => 'instant_jobs' do
  db do
    start_instant_reservations
    end_past_instant_reservations
  end
end

cron '*/1 * * * *', :mutex => 'periodic_jobs' do
  db do
    sleep 1
    end_past_normal_reservations
    start_active_reservations
    check_active_reservations
  end
end

def db(&block)
  begin
    ActiveRecord::Base.connection_pool.clear_stale_cached_connections!
    yield block
  rescue Exception => e
    raise e
  ensure
    ActiveRecord::Base.connection_pool.release_connection if ActiveRecord::Base.connection
  end
end

def end_past_normal_reservations
  unended_past_normal_reservations.map do |reservation|
    reservation.end_reservation
  end
end

def end_past_instant_reservations
  unended_past_instant_reservations.map do |reservation|
    reservation.end_reservation
  end
end

def unended_past_reservations
  Reservation.where('ends_at < ? AND provisioned = ? AND ended = ?', Time.current, true, false)
end

def unended_past_normal_reservations
  unended_past_reservations.where('end_instantly = ?', false)
end

def unended_past_instant_reservations
  unended_past_reservations.where('end_instantly = ?', true)
end

def end_reservation(reservations)
  reservations.map do |reservation|
    reservation.end_reservation
  end
end

def start_active_reservations
  unstarted_now_reservations  = now_reservations.where('provisioned = ? AND start_instantly = ?', false, false)
  start_reservations(unstarted_now_reservations)
end

def start_instant_reservations
  unstarted_instant_reservations = now_reservations.where('provisioned = ? AND start_instantly = ?', false, true)
  start_reservations(unstarted_instant_reservations)
end<commit_msg>fix instantly ending reservations<commit_after>every '1s', :mutex => 'instant_jobs' do
  db do
    start_instant_reservations
    end_past_instant_reservations
  end
end

cron '*/1 * * * *', :mutex => 'periodic_jobs' do
  db do
    sleep 1
    end_past_normal_reservations
    start_active_reservations
    check_active_reservations
  end
end

def db(&block)
  begin
    ActiveRecord::Base.connection_pool.clear_stale_cached_connections!
    yield block
  rescue Exception => e
    raise e
  ensure
    ActiveRecord::Base.connection_pool.release_connection if ActiveRecord::Base.connection
  end
end

def end_past_normal_reservations
  unended_past_normal_reservations.map do |reservation|
    reservation.end_reservation
  end
end

def unended_past_normal_reservations
  unended_past_reservations.where('end_instantly = ?', false)
end

def unended_past_reservations
  Reservation.where('ends_at < ? AND provisioned = ? AND ended = ?', Time.current, true, false)
end

def end_past_instant_reservations
  unended_past_instant_reservations.map do |reservation|
    reservation.end_reservation
  end
end

def unended_past_instant_reservations
  Reservation.where('provisioned = ? AND ended = ? AND end_instantly = ?', true, false, true)
end

def end_reservation(reservations)
  reservations.map do |reservation|
    reservation.end_reservation
  end
end

def start_active_reservations
  unstarted_now_reservations  = now_reservations.where('provisioned = ? AND start_instantly = ?', false, false)
  start_reservations(unstarted_now_reservations)
end

def start_instant_reservations
  unstarted_instant_reservations = now_reservations.where('provisioned = ? AND start_instantly = ?', false, true)
  start_reservations(unstarted_instant_reservations)
end
{'fraction_non_alphanumeric': 0.06850507982583454, 'fraction_numerical': 0.0017416545718432512, 'mean_word_length': 5.551330798479087, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '89577', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1139, 'n_words': 222}