diff --git a/mayan/apps/documents/apps.py b/mayan/apps/documents/apps.py index 7224b04b9c..39e9dcbafb 100644 --- a/mayan/apps/documents/apps.py +++ b/mayan/apps/documents/apps.py @@ -56,7 +56,10 @@ from .links import ( link_document_version_download, link_document_version_list, link_document_version_revert, link_trash_can_empty ) -from .literals import CHECK_DELETE_PERIOD_INTERVAL, CHECK_TRASH_PERIOD_INTERVAL +from .literals import ( + CHECK_DELETE_PERIOD_INTERVAL, CHECK_TRASH_PERIOD_INTERVAL, + DELETE_STALE_STUBS_INTERVAL +) from .models import ( DeletedDocument, Document, DocumentPage, DocumentType, DocumentTypeFilename, DocumentVersion @@ -183,6 +186,10 @@ class DocumentsApp(MayanAppConfig): 'task': 'documents.tasks.task_check_trash_periods', 'schedule': timedelta(seconds=CHECK_TRASH_PERIOD_INTERVAL), }, + 'task_delete_stubs': { + 'task': 'documents.tasks.task_delete_stubs', + 'schedule': timedelta(seconds=DELETE_STALE_STUBS_INTERVAL), + }, } ) @@ -208,6 +215,9 @@ class DocumentsApp(MayanAppConfig): 'documents.tasks.task_check_trash_periods': { 'queue': 'documents_periodic' }, + 'documents.tasks.task_delete_stubs': { + 'queue': 'documents_periodic' + }, 'documents.tasks.task_clear_image_cache': { 'queue': 'tools' }, diff --git a/mayan/apps/documents/literals.py b/mayan/apps/documents/literals.py index c4d8b4b812..468956b5fc 100644 --- a/mayan/apps/documents/literals.py +++ b/mayan/apps/documents/literals.py @@ -5,10 +5,12 @@ from django.utils.translation import ugettext_lazy as _ CACHE_PATH = 'document_cache/' CHECK_DELETE_PERIOD_INTERVAL = 60 CHECK_TRASH_PERIOD_INTERVAL = 60 +DELETE_STALE_STUBS_INTERVAL = 60 DEFAULT_DELETE_PERIOD = 30 DEFAULT_DELETE_TIME_UNIT = 'days' DEFAULT_ZIP_FILENAME = 'document_bundle.zip' DOCUMENT_IMAGE_TASK_TIMEOUT = 20 +STUB_EXPIRATION_INTERVAL = 60 * 60 * 24 # 24 hours UPDATE_PAGE_COUNT_RETRY_DELAY = 10 UPLOAD_NEW_VERSION_RETRY_DELAY = 10 NEW_DOCUMENT_RETRY_DELAY = 10 diff --git a/mayan/apps/documents/tasks.py b/mayan/apps/documents/tasks.py index c25bdf14fd..44f05d7565 100644 --- a/mayan/apps/documents/tasks.py +++ b/mayan/apps/documents/tasks.py @@ -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)