Change georeplication queuing to use new batch system
This commit is contained in:
parent
732ab67b57
commit
9413e25123
2 changed files with 31 additions and 11 deletions
|
@ -1,14 +1,34 @@
|
|||
import features
|
||||
import json
|
||||
|
||||
from contextlib import contextmanager
|
||||
from data import model
|
||||
|
||||
from app import image_replication_queue
|
||||
|
||||
DEFAULT_BATCH_SIZE = 1000
|
||||
|
||||
@contextmanager
|
||||
def queue_replication_batch(namespace, batch_size=DEFAULT_BATCH_SIZE):
|
||||
"""
|
||||
Context manager implementation which returns a target callable that takes the storage
|
||||
to queue for replication. When the the context block exits the items generated by
|
||||
the callable will be bulk inserted into the queue with the specified batch size.
|
||||
"""
|
||||
namespace_user = model.user.get_namespace_user(namespace)
|
||||
|
||||
with image_replication_queue.batch_insert(batch_size) as queue_put:
|
||||
def queue_storage_replication_batch(storage):
|
||||
if features.STORAGE_REPLICATION:
|
||||
queue_put([storage.uuid], json.dumps({
|
||||
'namespace_user_id': namespace_user.id,
|
||||
'storage_id': storage.uuid,
|
||||
}))
|
||||
|
||||
yield queue_storage_replication_batch
|
||||
|
||||
|
||||
def queue_storage_replication(namespace, storage):
|
||||
""" Queues replication for the given image storage under the given namespace (if enabled). """
|
||||
if features.STORAGE_REPLICATION:
|
||||
namespace_user = model.user.get_namespace_user(namespace)
|
||||
image_replication_queue.put([storage.uuid], json.dumps({
|
||||
'namespace_user_id': namespace_user.id,
|
||||
'storage_id': storage.uuid,
|
||||
}))
|
||||
with queue_replication_batch(namespace, 1) as batch_spawn:
|
||||
batch_spawn(storage)
|
||||
|
|
Reference in a new issue