1
0
mirror of https://github.com/quay/quay.git synced 2025-04-18 10:44:06 +03:00
quay/util/registry/replication.py
Brandon Caton 9eb4fb6aa4
Revert workqueue refactor (#1456)
Currently the prometheus and GC workers are not running correctly.
Reverting the following commits:
- 4e1a985e70
- dac183a1ef
- 68a0d9eaf0
- af1aacea08
- f334b80098
2022-07-22 13:11:39 -04:00

46 lines
1.3 KiB
Python

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).
"""
with queue_replication_batch(namespace, 1) as batch_spawn:
batch_spawn(storage)