Created
June 22, 2012 18:52
-
-
Save dpetzel/2974494 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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