Creates a data model for the document consumption, allowing stronger typing of arguments and setting of some information about the file only once

This commit is contained in:
Trenton H
2023-01-23 15:55:49 -08:00
parent 80be254441
commit 36a6df0bae
14 changed files with 596 additions and 433 deletions

View File

@@ -13,6 +13,9 @@ from typing import Set
from django.conf import settings
from django.core.management.base import BaseCommand
from django.core.management.base import CommandError
from documents.data_models import ConsumableDocument
from documents.data_models import DocumentMetadataOverrides
from documents.data_models import DocumentSource
from documents.models import Tag
from documents.parsers import is_file_ext_supported
from documents.tasks import consume_file
@@ -122,8 +125,11 @@ def _consume(filepath: str) -> None:
try:
logger.info(f"Adding {filepath} to the task queue.")
consume_file.delay(
filepath,
override_tag_ids=list(tag_ids) if tag_ids else None,
ConsumableDocument(
source=DocumentSource.ConsumeFolder,
original_file=filepath,
),
DocumentMetadataOverrides(tag_ids=tag_ids),
)
except Exception:
# Catch all so that the consumer won't crash.