Created
October 12, 2015 06:57
-
-
Save mitsuru793/a2dac5d4f83258a94d85 to your computer and use it in GitHub Desktop.
503エラーの時に再接続する
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 'open-uri' | |
| # 末尾に記述した数値のステータスコードを返してくれるwebサービス | |
| url = 'http://ozuma.sakura.ne.jp/httpstatus/503' | |
| def open_url(url) | |
| begin | |
| open(url) | |
| rescue OpenURI::HTTPError => e | |
| response = e.io | |
| # response.status => ["503", "Service Unavailable"] | |
| if response.status[0] == "503" | |
| puts "retry open" | |
| open_url(url) | |
| end | |
| end | |
| end | |
| open_url(url) | |
| # => retry open | |
| # retry open | |
| # retry open | |
| # 以下ループ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment