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. """
with UseThenDisconnect(app.config):
while True:
# Find all queue items older than the threshold (typically a week) that have no additional
# retries and delete them.
# Find all queue items older than the threshold (typically a week) and delete them.
threshold_ago = datetime.now() - DELETION_DATE_THRESHOLD
to_delete = list(QueueItem.select().where(QueueItem.processing_expires >= threshold_ago,
QueueItem.retries_remaining == 0)
to_delete = list(QueueItem.select()
.where(QueueItem.processing_expires <= threshold_ago)
.limit(BATCH_SIZE))
if len(to_delete) < DELETION_COUNT_THRESHOLD: