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:
@@ -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})
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user