diff --git a/src/palace/manager/celery/opds.py b/src/palace/manager/celery/opds.py index 9598f2dadf..d7f22bf99e 100644 --- a/src/palace/manager/celery/opds.py +++ b/src/palace/manager/celery/opds.py @@ -57,7 +57,9 @@ def opds_import_task[FeedType]( ) if not import_result: - task.log.info("Import failed, aborting task.") + task.log.info( + f"Import failed, aborting task for collection '{collection.name}' (id={collection.id})" + ) return None # If a post-import hook is provided, call it with the import result. @@ -81,8 +83,11 @@ def opds_import_task[FeedType]( if not should_continue: task.log.info( - f"Found unchanged publications in feed, stopping import without harvesting the rest of the feed." + f"Found unchanged publications in feed, stopping import without harvesting the rest of the feed" + f" for collection '{collection.name}' (id={collection.id}) " ) - task.log.info("Import complete.") + task.log.info( + f"Import complete for collection '{collection.name}' (id={collection.id})" + ) return identifier_set diff --git a/src/palace/manager/celery/tasks/opds_odl.py b/src/palace/manager/celery/tasks/opds_odl.py index 79b9df0361..a2d7dba7dc 100644 --- a/src/palace/manager/celery/tasks/opds_odl.py +++ b/src/palace/manager/celery/tasks/opds_odl.py @@ -345,7 +345,9 @@ def import_collection( ) if not import_result: - task.log.info("Import failed, aborting task.") + task.log.info( + f"Import failed, aborting task for collection '{collection.name}' (id={collection_id})." + ) return next_link = import_result.next_url @@ -360,4 +362,6 @@ def import_collection( ) ) - task.log.info("Import complete.") + task.log.info( + f"Import complete for collection '{collection.name}' (id={collection_id})." + ) diff --git a/src/palace/manager/integration/license/opds/importer.py b/src/palace/manager/integration/license/opds/importer.py index 677611b75a..917bd63ba7 100644 --- a/src/palace/manager/integration/license/opds/importer.py +++ b/src/palace/manager/integration/license/opds/importer.py @@ -358,7 +358,8 @@ def import_feed( feed = self._fetch_feed(feed_url) except ValueError as e: self.log.error( - f"Failed to fetch or parse the feed from '{feed_url}': {e}", + f"Failed to fetch or parse the feed from '{feed_url}' " + f"for collection '{collection.name}' (id={collection.id}): {e}", exc_info=e, ) return False @@ -405,11 +406,13 @@ def import_feed( if failures: self.log.error( - f"Failed to import {len(failures)} publications from '{feed_url}'." + f"Failed to import {len(failures)} publications from '{feed_url}' " + f"for collection '{collection.name}' (id={collection.id})." ) for failure in failures: self.log.error( - f"Failed to import publication: {failure.identifier} ({failure.title})" + f"Failed to import publication: {failure.identifier} ({failure.title}) " + f"for collection '{collection.name}' (id={collection.id})" f" - {failure.error_message}: {failure.error}", exc_info=failure.error, extra={"palace_publication_data": failure.publication_data}, diff --git a/tests/manager/celery/tasks/test_opds1.py b/tests/manager/celery/tasks/test_opds1.py index f54d50f222..72fb2b5723 100644 --- a/tests/manager/celery/tasks/test_opds1.py +++ b/tests/manager/celery/tasks/test_opds1.py @@ -579,6 +579,9 @@ def test_parse_identifier( opds_files_fixture: OPDSFilesFixture, caplog: pytest.LogCaptureFixture, ) -> None: + + collection = opds1_import_fixture.collection + # Normal case, we just call out to Identifier.parse_urn expected_identifier = IdentifierData( type=Identifier.URI, identifier="https://example.com/12345" @@ -607,7 +610,7 @@ def test_parse_identifier( ) opds1_import_fixture.run_import_task(apply=True) assert ( - "https://unglue.it/api/id/work/7775/ (Warbreaker) - " + f"https://unglue.it/api/id/work/7775/ (Warbreaker) for collection '{collection.name}' (id={collection.id}) - " "Could not extract an identifier from the publication: My god, it's full of stars" in caplog.text ) diff --git a/tests/manager/celery/tasks/test_opds2.py b/tests/manager/celery/tasks/test_opds2.py index c3ad88db96..a0e5fb483d 100644 --- a/tests/manager/celery/tasks/test_opds2.py +++ b/tests/manager/celery/tasks/test_opds2.py @@ -903,6 +903,7 @@ def test_import_multiple_pages( 3. Re-import with force continues through all pages despite unchanged publications """ caplog.set_level(LogLevel.info) + collection = opds2_import_fixture.collection # First import: Import both pages successfully # feed2 has a next link to feed, which has no next link. @@ -949,7 +950,10 @@ def test_import_multiple_pages( # Should NOT see the log message about stopping due to unchanged publications assert "Found unchanged publications in feed" not in caplog.text # Should see the log message about completing the import - assert "Import complete." in caplog.text + assert ( + f"Import complete for collection '{collection.name}' (id={collection.id})" + in caplog.text + ) # Should have 6 tasks queued (3 from each page) even though publications are unchanged assert len(apply_task_fixture.apply_queue) == 6 diff --git a/tests/manager/celery/tasks/test_opds_odl.py b/tests/manager/celery/tasks/test_opds_odl.py index f6f6ce7616..f296694876 100644 --- a/tests/manager/celery/tasks/test_opds_odl.py +++ b/tests/manager/celery/tasks/test_opds_odl.py @@ -867,7 +867,8 @@ def test_import( # 4. Make sure that the failure is covered assert ( - "Failed to import publication: urn:isbn:9781234567897 (None) - Error validating publication: 2 validation errors" + f"Failed to import publication: urn:isbn:9781234567897 (None) for collection '{collection.name}' " + f"(id={collection.id}) - Error validating publication: 2 validation errors" in caplog.text )