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.
This commit is contained in:
Elrond
2012-01-29 20:56:51 +01:00
parent b8e635b22f
commit 82cd968347
3 changed files with 22 additions and 10 deletions

View File

@@ -290,3 +290,14 @@ class MigrationManager(object):
self.set_current_migration(migration_number)
if post_callback:
post_callback(migration_number, migration_func)
##########################
# Random utility functions
##########################
def atomic_update(table, query_dict, update_values):
table.collection.update(
query_dict,
{"$set": update_values})

View File

@@ -22,4 +22,5 @@ except ImportError:
if use_sql:
from mediagoblin.db.sql.fake import ObjectId, InvalidId, DESCENDING
else:
from mediagoblin.db.mongo.util import ObjectId, InvalidId, DESCENDING
from mediagoblin.db.mongo.util import \
ObjectId, InvalidId, DESCENDING, atomic_update