Last active
August 29, 2015 14:24
-
-
Save Winslett/8e0ab9066d4888ee760e to your computer and use it in GitHub Desktop.
ruby-pg connection retry from PG::UnableToSend
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
uri = URI.parse(ENV['POSTGRES_URL']) | |
$query_postgres = lambda do |sql| | |
begin | |
$postgres ||= PG.connect(uri.hostname, uri.port, nil, nil, uri.path[1..-1], uri.user, uri.password) | |
$postgres.exec(sql) | |
rescue PG::UnableToSend | |
$postgres = nil | |
retry | |
end | |
end | |
result = $query_postgres.call("SELECT * FROM accounts") | |
result.each do |row| | |
row.each do |key, value| | |
puts [key, value].join("=") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment