<commit_before>require "redis"
require "pg"

def log(message)
  puts "\e[34m#{message}\e[0m"
end

log "Checking Redis server..."
redis = Redis.new()
log "REDIS VERSION: #{redis.info["redis_version"]}"

sleep 2

log "Checking PostgreSQL server..."
pg = PG.connect({
  host: ENV['POSTGRES_HOST'],
  dbname: ENV['POSTGRES_DB'],
  user: ENV['POSTGRES_USER']
  })
log pg.exec("SELECT version();").first["version"]
<commit_msg>Proper exception handling and remove sleep<commit_after>require "redis"
require "pg"

def log(message)
  puts "\e[34m#{message}\e[0m"
end

log "Checking Redis server..."
begin
  redis = Redis.new()
  redis.ping
  log "REDIS VERSION: #{redis.info["redis_version"]}"
rescue Redis::CannotConnectError => e
  STDERR.puts(e.message)
  exit 1
end


log "Checking PostgreSQL server..."
begin
  pg = PG.connect({
    host: ENV['POSTGRES_HOST'],
    dbname: ENV['POSTGRES_DB'],
    user: ENV['POSTGRES_USER'],
    connect_timeout: 10
    })
  log pg.exec("SELECT version();").first["version"]
rescue PG::Error => e
  STDERR.puts("PostgreSQL connection faild")
  exit 2
end

{'fraction_non_alphanumeric': 0.1640552995391705, 'fraction_numerical': 0.010138248847926268, 'mean_word_length': 4.626943005181347, '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': '1280722', 'n_tokens_mistral': 416, 'n_tokens_neox': 411, 'n_words': 96}