diff --git a/src/documents/consumer.py b/src/documents/consumer.py index 71b1294f5..f4a40cbb9 100755 --- a/src/documents/consumer.py +++ b/src/documents/consumer.py @@ -35,6 +35,7 @@ class Consumer(LoggingMixin): message, document_id=None): payload = { 'filename': os.path.basename(filename), + 'task_id': self.task_id, 'current_progress': current_progress, 'max_progress': max_progress, 'status': status, @@ -58,6 +59,7 @@ class Consumer(LoggingMixin): self.override_correspondent_id = None self.override_tag_ids = None self.override_document_type_id = None + self.task_id = None self.channel_layer = get_channel_layer() @@ -136,7 +138,8 @@ class Consumer(LoggingMixin): override_title=None, override_correspondent_id=None, override_document_type_id=None, - override_tag_ids=None): + override_tag_ids=None, + task_id=None): """ Return the document object if it was successfully created. """ @@ -147,6 +150,7 @@ class Consumer(LoggingMixin): self.override_correspondent_id = override_correspondent_id self.override_document_type_id = override_document_type_id self.override_tag_ids = override_tag_ids + self.task_id = task_id self._send_progress(self.filename, 0, 100, 'WORKING', 'Received new file.') diff --git a/src/documents/tasks.py b/src/documents/tasks.py index 38ff532b5..c67b2b3fa 100644 --- a/src/documents/tasks.py +++ b/src/documents/tasks.py @@ -62,7 +62,8 @@ def consume_file(path, override_title=None, override_correspondent_id=None, override_document_type_id=None, - override_tag_ids=None): + override_tag_ids=None, + task_id=None): document = Consumer().try_consume_file( path, @@ -70,7 +71,9 @@ def consume_file(path, override_title=override_title, override_correspondent_id=override_correspondent_id, override_document_type_id=override_document_type_id, - override_tag_ids=override_tag_ids) + override_tag_ids=override_tag_ids, + task_id=task_id + ) if document: return "Success. New document id {} created".format( diff --git a/src/documents/views.py b/src/documents/views.py index f0c7f10d1..2012e879a 100755 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -1,6 +1,7 @@ import logging import os import tempfile +import uuid from datetime import datetime from time import mktime @@ -385,6 +386,8 @@ class PostDocumentView(APIView): f.write(doc_data) os.utime(f.name, times=(t, t)) + task_id = str(uuid.uuid4()) + async_task("documents.tasks.consume_file", f.name, override_filename=doc_name, @@ -392,8 +395,9 @@ class PostDocumentView(APIView): override_correspondent_id=correspondent_id, override_document_type_id=document_type_id, override_tag_ids=tag_ids, + task_id=task_id, task_name=os.path.basename(doc_name)[:100]) - return Response("OK") + return Response({"task_id": task_id}) class SelectionDataView(APIView):