Add support for deleting namespaces (users, organizations)
Fixes #102 Fixes #105
This commit is contained in:
parent
a74e94fb67
commit
73eb66eac5
23 changed files with 407 additions and 33 deletions
|
@ -33,12 +33,14 @@ class BuildMetricQueueReporter(object):
|
|||
class WorkQueue(object):
|
||||
""" Work queue defines methods for interacting with a queue backed by the database. """
|
||||
def __init__(self, queue_name, transaction_factory,
|
||||
canonical_name_match_list=None, reporter=None, metric_queue=None):
|
||||
canonical_name_match_list=None, reporter=None, metric_queue=None,
|
||||
has_namespace=False):
|
||||
self._queue_name = queue_name
|
||||
self._reporter = reporter
|
||||
self._metric_queue = metric_queue
|
||||
self._transaction_factory = transaction_factory
|
||||
self._currently_processing = False
|
||||
self._has_namespaced_items = has_namespace
|
||||
|
||||
if canonical_name_match_list is None:
|
||||
self._canonical_name_match_list = []
|
||||
|
@ -130,6 +132,15 @@ class WorkQueue(object):
|
|||
except QueueItem.DoesNotExist:
|
||||
return False
|
||||
|
||||
def delete_namespaced_items(self, namespace, subpath=None):
|
||||
""" Deletes all items in this queue that exist under the given namespace. """
|
||||
if not self._has_namespaced_items:
|
||||
return False
|
||||
|
||||
subpath_query = '%s/' % subpath if subpath else ''
|
||||
queue_prefix = '%s/%s/%s%%' % (self._queue_name, namespace, subpath_query)
|
||||
QueueItem.delete().where(QueueItem.queue_name ** queue_prefix).execute()
|
||||
|
||||
def put(self, canonical_name_list, message, available_after=0, retries_remaining=5):
|
||||
"""
|
||||
Put an item, if it shouldn't be processed for some number of seconds,
|
||||
|
|
Reference in a new issue