Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ekirjasto 18 show failed items during opds import #107

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions core/opds_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -1958,20 +1958,29 @@ def _get_feeds(self) -> Iterable[tuple[str, bytes]]:
return reversed(feeds)

def run_once(self, progress: TimestampData) -> TimestampData:
"""
Import all books in a feed.

:param progress: A TimestampData object indicating the start time of the run.
:return: A new TimestampData object with an achievements field
containing details of the operation.
"""
feeds = self._get_feeds()
total_imported = 0
total_failures = 0
failure_summary = []

for link, feed in feeds:
self.log.info("Importing next feed: %s", link)
imported_editions, failures = self.import_one_feed(feed)
total_imported += len(imported_editions)
total_failures += len(failures)
for failure_id, failure_details in failures.items():
failure_summary.append(f"ISBN: {failure_id}: {failure_details}")
self._db.commit()

achievements = "Items imported: %d. Failures: %d." % (
total_imported,
total_failures,
achievements = (
"Items imported: %d. Failures: %d.\nFailed IDs and details:\n%s"
% (total_imported, total_failures, "\n".join(failure_summary))
)

return TimestampData(achievements=achievements)
6 changes: 4 additions & 2 deletions tests/core/test_opds_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -1948,7 +1948,7 @@ def test_import_one_feed(self, opds_importer_fixture: OPDSImporterFixture):
collection=collection,
)
assert "Utter failure!" in failure.exception

print(failures)
# Both failures were reported in the return value from
# import_one_feed
assert 2 == len(failures)
Expand Down Expand Up @@ -1992,7 +1992,9 @@ def import_one_feed(self, feed):
assert ["last page", "second page", "first page"] == monitor.imports

# Every page of the import had two successes and one failure.
assert "Items imported: 6. Failures: 3." == progress.achievements
assert (
"Items imported: 6. Failures: 3.\nFailed IDs and details:\nISBN: identifier: Failure\nISBN: identifier: Failure\nISBN: identifier: Failure"
) == progress.achievements

# The TimestampData returned by run_once does not include any
# timing information; that's provided by run().
Expand Down