Skip to content

Commit

Permalink
Db scheduler: Handle database errors occuring at sync
Browse files Browse the repository at this point in the history
  • Loading branch information
ask committed May 8, 2012
1 parent 3835ea9 commit c60a396
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
29 changes: 18 additions & 11 deletions djcelery/schedulers.py
Expand Up @@ -164,18 +164,25 @@ def reserve(self, entry):
@transaction.commit_manually
def sync(self):
self.logger.debug("Writing dirty entries...")
_tried = set()
try:
while self._dirty:
try:
name = self._dirty.pop()
self.schedule[name].save()
except (KeyError, ObjectDoesNotExist):
pass
except:
transaction.rollback()
raise
else:
transaction.commit()
try:
while self._dirty:
try:
name = self._dirty.pop()
_tried.add(name)
self.schedule[name].save()
except (KeyError, ObjectDoesNotExist):
pass
except:
transaction.rollback()
raise
else:
transaction.commit()
except DATABASE_ERRORS, exc:
# retry later
self._dirty |= _tried
warn(RuntimeWarning("Database error while sync: %r" % (exc, )))

def update_from_dict(self, dict_):
s = {}
Expand Down
16 changes: 12 additions & 4 deletions djcelery/utils.py
Expand Up @@ -10,22 +10,30 @@
from django.db import DatabaseError
try:
import MySQLdb as mysql
_my_database_errors = (mysql.DatabaseError, )
_my_database_errors = (mysql.DatabaseError,
mysql.InterfaceError,
mysql.OperationalError)
except ImportError:
_my_database_errors = () # noqa
try:
import psycopg2 as pg
_pg_database_errors = (pg.DatabaseError, )
_pg_database_errors = (pg.DatabaseError,
pg.InterfaceError,
pg.OperationalError)
except ImportError:
_pg_database_errors = () # noqa
try:
import sqlite3
_lite_database_errors = (sqlite3.DatabaseError, )
_lite_database_errors = (sqlite3.DatabaseError,
sqlite3.InterfaceError,
sqlite3.OperationalError)
except ImportError:
_lite_database_errors = () # noqa
try:
import cx_Oracle as oracle
_oracle_database_errors = (oracle.DatabaseError, )
_oracle_database_errors = (oracle.DatabaseError,
oracle.InterfaceError,
oracle.OperationalError)
except ImportError:
_oracle_database_errors = () # noqa

Expand Down

0 comments on commit c60a396

Please sign in to comment.