diff options
author | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2012-01-29 20:56:51 +0100 |
---|---|---|
committer | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2012-03-04 20:58:19 +0100 |
commit | 82cd968347988f61ac52c2100d1dc47750decead (patch) | |
tree | 7466d3b3b7d9ebda568c3ad4eeb8ed92d4215efb /mediagoblin/processing.py | |
parent | b8e635b22f9647b173b9320ebb6539bdefe851d8 (diff) | |
download | mediagoblin-82cd968347988f61ac52c2100d1dc47750decead.tar.lz mediagoblin-82cd968347988f61ac52c2100d1dc47750decead.tar.xz mediagoblin-82cd968347988f61ac52c2100d1dc47750decead.zip |
Create atomic_update db utility function
In some cases (notably the mark_entry_failed function) it
is useful to have atomic update functionality on the db. On
mongo this requires special syntax.
So created an atomic_update function for mongo and started
to use it in mark_entry_failed.
Diffstat (limited to 'mediagoblin/processing.py')
-rw-r--r-- | mediagoblin/processing.py | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/mediagoblin/processing.py b/mediagoblin/processing.py index a07de869..1c84c557 100644 --- a/mediagoblin/processing.py +++ b/mediagoblin/processing.py @@ -18,7 +18,7 @@ import logging from celery.task import Task -from mediagoblin.db.util import ObjectId +from mediagoblin.db.util import ObjectId, atomic_update from mediagoblin import mg_globals as mgg from mediagoblin.tools.translate import lazy_pass_to_ugettext as _ @@ -108,22 +108,22 @@ def mark_entry_failed(entry_id, exc): if isinstance(exc, BaseProcessingFail): # Looks like yes, so record information about that failure and any # metadata the user might have supplied. - mgg.database['media_entries'].update( + atomic_update(mgg.database.MediaEntry, {'_id': entry_id}, - {'$set': {u'state': u'failed', - u'fail_error': exc.exception_path, - u'fail_metadata': exc.metadata}}) + {u'state': u'failed', + u'fail_error': exc.exception_path, + u'fail_metadata': exc.metadata}) else: _log.warn("No idea what happened here, but it failed: %r", exc) # Looks like no, so just mark it as failed and don't record a # failure_error (we'll assume it wasn't handled) and don't record # metadata (in fact overwrite it if somehow it had previous info # here) - mgg.database['media_entries'].update( + atomic_update(mgg.database.MediaEntry, {'_id': entry_id}, - {'$set': {u'state': u'failed', - u'fail_error': None, - u'fail_metadata': {}}}) + {u'state': u'failed', + u'fail_error': None, + u'fail_metadata': {}}) class BaseProcessingFail(Exception): |