workers.queuecleanup: remove direct peewee usage
This commit is contained in:
parent
efbbeeb07f
commit
20ef43d5fb
2 changed files with 28 additions and 11 deletions
|
@ -274,3 +274,21 @@ class WorkQueue(object):
|
|||
except QueueItem.DoesNotExist:
|
||||
return
|
||||
|
||||
|
||||
def delete_expired(expiration_threshold, deletion_threshold, batch_size):
|
||||
"""
|
||||
Deletes all queue items that are older than the provided expiration threshold in batches of the
|
||||
provided size. If there are less items than the deletion threshold, this method does nothing.
|
||||
|
||||
Returns the number of items deleted.
|
||||
"""
|
||||
to_delete = list(QueueItem
|
||||
.select()
|
||||
.where(QueueItem.processing_expires <= expiration_threshold)
|
||||
.limit(batch_size))
|
||||
|
||||
if len(to_delete) < deletion_threshold:
|
||||
return 0
|
||||
|
||||
QueueItem.delete().where(QueueItem.id << to_delete).execute()
|
||||
return len(to_delete)
|
||||
|
|
Reference in a new issue