This commit is contained in:
shamoon 2025-06-23 09:34:29 -07:00
parent 0f6e9d4343
commit f819d8025c
No known key found for this signature in database

View File

@ -467,6 +467,7 @@ class ConsumerPlugin(
)
# now that everything is done, we can start to store the document
# in the system. This will be a transaction and reasonably fast.
success = False
try:
with transaction.atomic():
# store the document.
@ -530,9 +531,17 @@ class ConsumerPlugin(
# Don't save with the lock active. Saving will cause the file
# renaming logic to acquire the lock as well.
# This triggers things like file renaming
try:
document.save()
success = True
except Exception as e:
self._fail(
str(e),
f"The following error occurred while storing document "
f"{self.filename} after parsing: {e}",
exc_info=True,
exception=e,
)
finally:
if success:
# Delete the file only if it was successfully consumed
@ -551,22 +560,6 @@ class ConsumerPlugin(
if Path(shadow_file).is_file():
self.log.debug(f"Deleting file {shadow_file}")
Path(shadow_file).unlink()
else:
self.log.warning(
f"Document was not saved. Skipping file deletion for {self.filename}",
)
except Exception as e:
self._fail(
str(e),
f"The following error occurred while storing document "
f"{self.filename} after parsing: {e}",
exc_info=True,
exception=e,
)
finally:
document_parser.cleanup()
tempdir.cleanup()
self.run_post_consume_script(document)
@ -583,7 +576,16 @@ class ConsumerPlugin(
# Return the most up to date fields
document.refresh_from_db()
return f"Success. New document id {document.pk} created"
result = f"Success. New document id {document.pk} created"
else:
self._fail(
ConsumerStatusShortMessage.FAILED,
f"Document {self.filename} was not saved.",
)
document_parser.cleanup()
tempdir.cleanup()
return result
def _parse_title_placeholders(self, title: str) -> str:
local_added = timezone.localtime(timezone.now())