Last active
July 31, 2016 17:29
-
-
Save adamhooper/6a0752798fe0cd2922aa914f2c329198 to your computer and use it in GitHub Desktop.
2016-07-31 Timeout::timeout() buggy code
This file contains hidden or 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 'net/http' | |
require 'timeout' | |
require 'mysql2' # https://github.com/brianmario/mysql2 | |
def download_to_database(url, sql_statement) | |
Timeout::timeout(5) do # BUG. Never do this. | |
res = Net::HTTP.get_response(url) | |
sql_statement.execute(url.to_s, res.code, res.body) | |
end | |
end | |
client = Mysql2::Client.new(...) | |
statement = client.prepare( | |
"INSERT INTO http_responses (url, status_code, body) VALUES (?, ?, ?)" | |
) | |
download_to_database(URI('http://example.com'), statement) | |
download_to_database(URI('http://example.org'), statement) | |
# ... et cetera |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment