Created
November 16, 2011 19:44
-
-
Save repeatedly/1371114 to your computer and use it in GitHub Desktop.
Check reconnection in Mongo-Ruby-Driver
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 'mongo' | |
| c = Mongo::Connection.new.db('fluent').collection('a') | |
| i = 0 | |
| loop { | |
| begin | |
| c.insert({'a' => i}) | |
| i += 1 | |
| p "alive! #{i}" | |
| sleep(1) | |
| rescue | |
| p "Down!" | |
| sleep(2) | |
| end | |
| } | |
| __END__ | |
| Result: | |
| % ruby reconnection_test.rb | |
| "alive! 1" | |
| "alive! 2" | |
| "alive! 3" | |
| "alive! 4" | |
| "alive! 5" | |
| "alive! 6" | |
| "alive! 7" | |
| "alive! 8" | |
| "Down!" | |
| "Down!" | |
| "Down!" | |
| "Down!" | |
| "alive! 9" | |
| "alive! 10" | |
| "alive! 11" | |
| "alive! 12" | |
| "alive! 13" | |
| ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment