Skip to content

Instantly share code, notes, and snippets.

@dpetzel dpetzel/gist:2974494
Created Jun 22, 2012

Embed
What would you like to do?
def _commit_change(self, safe=False):
"""
A wrapper around transaction.commit so we can catch, log, retry
@type safe: Boolean
@param safe: Indicates if a safe commit is required.
Sometimes its OK if the commit fails. When set to false,
will raise an exception, instead of just logging it
@rtype: Boolean
@return: Boolean indicating result of commit attempt
"""
res = True
try:
commit()
except ConflictError as e:
log.warn("Conflict Detecting when trying to commit. Going to sync and retry")
conn.syncdb()
try:
commit()
except ConflictError as e2:
#It ain't good, but we should push forward and try and finish the rules
log.error("Commit failed again with conflict. Moving onto next item", e2)
if safe == False:
res = False
else:
raise
#Sync for good measure
conn.syncdb()
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.