Fix the queue cleanup worker to delete the items that have expired, not unexpired

This commit is contained in:
Joseph Schorr 2016-06-03 22:14:14 -04:00
parent 7d356c451b
commit dd0dd39bf0

View file

@ -21,11 +21,10 @@ class QueueCleanupWorker(Worker):
""" Performs garbage collection on the queueitem table. """ """ Performs garbage collection on the queueitem table. """
with UseThenDisconnect(app.config): with UseThenDisconnect(app.config):
while True: while True:
# Find all queue items older than the threshold (typically a week) that have no additional # Find all queue items older than the threshold (typically a week) and delete them.
# retries and delete them.
threshold_ago = datetime.now() - DELETION_DATE_THRESHOLD threshold_ago = datetime.now() - DELETION_DATE_THRESHOLD
to_delete = list(QueueItem.select().where(QueueItem.processing_expires >= threshold_ago, to_delete = list(QueueItem.select()
QueueItem.retries_remaining == 0) .where(QueueItem.processing_expires <= threshold_ago)
.limit(BATCH_SIZE)) .limit(BATCH_SIZE))
if len(to_delete) < DELETION_COUNT_THRESHOLD: if len(to_delete) < DELETION_COUNT_THRESHOLD: