Changeset 302 for trunk


Ignore:
Timestamp:
Mar 28, 2008, 10:19:05 PM (17 years ago)
Author:
ecprice
Message:

Work around stale database connections (#4) in the DNS server

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/sipb-xen-dns/code/dnsserver.py

    r300 r302  
    88
    99import sipb_xen_database
     10import psycopg2
     11import sqlalchemy
     12import time
    1013
    1114class DatabaseAuthority(common.ResolverBase):
     
    2427                                  expire=3600000, minimum=21600, ttl=3600)
    2528    def _lookup(self, name, cls, type, timeout = None):
     29        for i in range(3):
     30            try:
     31                value = self._lookup_unsafe(name, cls, type, timeout = None)
     32            except (psycopg2.OperationalError, sqlalchemy.exceptions.SQLError):
     33                if i == 2:
     34                    raise
     35                print "Reloading database"
     36                time.sleep(0.5)
     37                continue
     38            else:
     39                return value
     40
     41    def _lookup_unsafe(self, name, cls, type, timeout):
    2642        sipb_xen_database.clear_cache()
    2743        if not (name.lower() == self.domain or
Note: See TracChangeset for help on using the changeset viewer.