Add scheduled task to delete stale document stubs.

This commit is contained in:
Roberto Rosario
2015-09-08 18:38:24 -04:00
parent 02353927db
commit 43e1ffbc24
3 changed files with 26 additions and 2 deletions

View File

@@ -13,7 +13,7 @@ from common.models import SharedUploadedFile
from .literals import (
UPDATE_PAGE_COUNT_RETRY_DELAY, UPLOAD_NEW_VERSION_RETRY_DELAY,
NEW_DOCUMENT_RETRY_DELAY
NEW_DOCUMENT_RETRY_DELAY, STUB_EXPIRATION_INTERVAL
)
from .models import (
DeletedDocument, Document, DocumentPage, DocumentType, DocumentVersion
@@ -41,6 +41,7 @@ def task_check_delete_periods():
document_type, delta
)
for document in DeletedDocument.objects.filter(document_type=document_type):
# TODO: Don't iterate, filter documents by expiration
if now() > document.deleted_date_time + delta:
logger.info(
'Document "%s" with id: %d, trashed on: %s, exceded '
@@ -75,6 +76,7 @@ def task_check_trash_periods():
document_type, delta
)
for document in Document.objects.filter(document_type=document_type):
# TODO: Don't iterate, filter documents by expiration
if now() > document.date_added + delta:
logger.info(
'Document "%s" with id: %d, added on: %s, exceded '
@@ -98,6 +100,16 @@ def task_clear_image_cache():
logger.info('Finished document cache invalidation')
@app.task(ignore_result=True)
def task_delete_stubs():
logger.info('Executing')
for stale_stub_document in Document.objects.filter(is_stub=True, date_added__lt=now() - timedelta(seconds=STUB_EXPIRATION_INTERVAL)):
stale_stub_document.delete(trash=False)
logger.info('Finshed')
@app.task(compression='zlib')
def task_get_document_page_image(document_page_id, *args, **kwargs):
document_page = DocumentPage.objects.get(pk=document_page_id)