Skip to content

Instantly share code, notes, and snippets.

@johncosta
Created October 16, 2012 01:01
Show Gist options
  • Save johncosta/3896693 to your computer and use it in GitHub Desktop.
Save johncosta/3896693 to your computer and use it in GitHub Desktop.
Reworked waitfordb.py file example
#!/usr/bin/env python
from wsgi import *
from django.contrib.auth.models import User
from pymongo.errors import AutoReconnect, ConfigurationError
import time
deadline = time.time() + 600
while time.time() < deadline:
try:
User.objects.count()
print 'Successfully connected to database.'
exit(0)
except AutoReconnect:
print 'Could not connect to database. Waiting a little bit.'
time.sleep(10)
except ConfigurationError:
print 'Could not connect to database. Waiting a little bit.'
time.sleep(10)
print 'Could not connect to database after 10 minutes. Something is wrong.'
exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment