Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mkwiatkowski/5822838 to your computer and use it in GitHub Desktop.
Save mkwiatkowski/5822838 to your computer and use it in GitHub Desktop.
# Connect to the database.
db = Mongo::MongoClient.new.db("database")
begin
# Do an operation within 1 second limit.
Timeout.timeout(1) do
db["collection"].insert({'attribute' => 'value'})
end
rescue Timeout::Error
# Do something else in case of a timeout.
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment