This commit is contained in:
jonaswinkler 2021-01-26 00:51:20 +01:00
parent f31073a341
commit 339e96b63c
3 changed files with 15 additions and 4 deletions

View File

@ -35,6 +35,7 @@ class Consumer(LoggingMixin):
message, document_id=None): message, document_id=None):
payload = { payload = {
'filename': os.path.basename(filename), 'filename': os.path.basename(filename),
'task_id': self.task_id,
'current_progress': current_progress, 'current_progress': current_progress,
'max_progress': max_progress, 'max_progress': max_progress,
'status': status, 'status': status,
@ -58,6 +59,7 @@ class Consumer(LoggingMixin):
self.override_correspondent_id = None self.override_correspondent_id = None
self.override_tag_ids = None self.override_tag_ids = None
self.override_document_type_id = None self.override_document_type_id = None
self.task_id = None
self.channel_layer = get_channel_layer() self.channel_layer = get_channel_layer()
@ -136,7 +138,8 @@ class Consumer(LoggingMixin):
override_title=None, override_title=None,
override_correspondent_id=None, override_correspondent_id=None,
override_document_type_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. 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_correspondent_id = override_correspondent_id
self.override_document_type_id = override_document_type_id self.override_document_type_id = override_document_type_id
self.override_tag_ids = override_tag_ids self.override_tag_ids = override_tag_ids
self.task_id = task_id
self._send_progress(self.filename, 0, 100, 'WORKING', self._send_progress(self.filename, 0, 100, 'WORKING',
'Received new file.') 'Received new file.')

View File

@ -62,7 +62,8 @@ def consume_file(path,
override_title=None, override_title=None,
override_correspondent_id=None, override_correspondent_id=None,
override_document_type_id=None, override_document_type_id=None,
override_tag_ids=None): override_tag_ids=None,
task_id=None):
document = Consumer().try_consume_file( document = Consumer().try_consume_file(
path, path,
@ -70,7 +71,9 @@ def consume_file(path,
override_title=override_title, override_title=override_title,
override_correspondent_id=override_correspondent_id, override_correspondent_id=override_correspondent_id,
override_document_type_id=override_document_type_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: if document:
return "Success. New document id {} created".format( return "Success. New document id {} created".format(

View File

@ -1,6 +1,7 @@
import logging import logging
import os import os
import tempfile import tempfile
import uuid
from datetime import datetime from datetime import datetime
from time import mktime from time import mktime
@ -385,6 +386,8 @@ class PostDocumentView(APIView):
f.write(doc_data) f.write(doc_data)
os.utime(f.name, times=(t, t)) os.utime(f.name, times=(t, t))
task_id = str(uuid.uuid4())
async_task("documents.tasks.consume_file", async_task("documents.tasks.consume_file",
f.name, f.name,
override_filename=doc_name, override_filename=doc_name,
@ -392,8 +395,9 @@ class PostDocumentView(APIView):
override_correspondent_id=correspondent_id, override_correspondent_id=correspondent_id,
override_document_type_id=document_type_id, override_document_type_id=document_type_id,
override_tag_ids=tag_ids, override_tag_ids=tag_ids,
task_id=task_id,
task_name=os.path.basename(doc_name)[:100]) task_name=os.path.basename(doc_name)[:100])
return Response("OK") return Response({"task_id": task_id})
class SelectionDataView(APIView): class SelectionDataView(APIView):