feat(ingest): ensure session rollback on ingestion error and log mention count
This commit is contained in:
@@ -159,13 +159,14 @@ async def ingest_file(session: AsyncSession, path: Path | AsyncPath, config: Ebo
|
|||||||
await session.flush()
|
await session.flush()
|
||||||
chunk_index = add_chapter_chunks(session, source, chapter, parsed_chapter, chunk_index, config)
|
chunk_index = add_chapter_chunks(session, source, chapter, parsed_chapter, chunk_index, config)
|
||||||
|
|
||||||
await session.commit()
|
|
||||||
mention_count = await index_chunk_phrase_mentions_for_book(session, source.id, config)
|
mention_count = await index_chunk_phrase_mentions_for_book(session, source.id, config)
|
||||||
|
await session.commit()
|
||||||
logger.info(
|
logger.info(
|
||||||
f"ebook_ingest_file_complete {source.id=} {resolved_path=} chapters={len(parsed.chapters)} {chunk_index=} "
|
f"ebook_ingest_file_complete {source.id=} {resolved_path=} chapters={len(parsed.chapters)} {chunk_index=} "
|
||||||
f"{mention_count=}"
|
f"{mention_count=}"
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
await session.rollback()
|
||||||
logger.exception(f"ebook_ingest_file_error {path=}")
|
logger.exception(f"ebook_ingest_file_error {path=}")
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user