Created
October 15, 2012 19:19
-
-
Save johanneswuerbach/3894559 to your computer and use it in GitHub Desktop.
Test database connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "mysql" | |
require "json" | |
db_host = "" | |
db_user = "" | |
db_pass = "" | |
db_name = "" | |
# Test database conneciton | |
requests = 0 | |
errors = 0 | |
while true | |
requests += 1 | |
begin | |
db = Mysql.init | |
db.options(Mysql::OPT_READ_TIMEOUT, 2) | |
db.real_connect(db_host, db_user, db_pass, db_name) | |
db.query("SHOW TABLES") | |
puts "DB: OK (#{errors} / #{requests})" | |
rescue Mysql::Error => err | |
errors += 1 | |
puts "DB: Error (#{errors} / #{requests})" | |
end | |
sleep 2 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment