diff --git a/src/palace/manager/celery/tasks/marc.py b/src/palace/manager/celery/tasks/marc.py index 3462e39dd..dd2f7871d 100644 --- a/src/palace/manager/celery/tasks/marc.py +++ b/src/palace/manager/celery/tasks/marc.py @@ -64,13 +64,27 @@ def marc_export(task: Task, force: bool = False) -> None: needs_delta = [l.model_dump() for l in libraries_info if l.last_updated] if needs_delta: - marc_export_collection.delay( - collection_id=collection.id, - collection_name=collection.name, - start_time=start_time, - libraries=needs_delta, - delta=True, + min_last_updated = min( + [l.last_updated for l in libraries_info if l.last_updated] ) + if not MarcExporter.query_works( + session, + collection.id, + batch_size=1, + last_updated=min_last_updated, + ): + task.log.info( + f"Skipping delta for collection {collection.name} ({collection.id}) " + f"because no works have been updated." + ) + else: + marc_export_collection.delay( + collection_id=collection.id, + collection_name=collection.name, + start_time=start_time, + libraries=needs_delta, + delta=True, + ) def marc_export_collection_lock( diff --git a/tests/manager/celery/tasks/test_marc.py b/tests/manager/celery/tasks/test_marc.py index 9516b6e9c..798d5de3f 100644 --- a/tests/manager/celery/tasks/test_marc.py +++ b/tests/manager/celery/tasks/test_marc.py @@ -115,15 +115,24 @@ def test_skip_collections( library=marc_exporter_fixture.library1, ) - # Collection 3 should be skipped because it was updated recently - marc_exporter_fixture.work(marc_exporter_fixture.collection3) + # Collection 3 should get a full export, but not a delta, because + # its work hasn't been updated since the last full export + work = marc_exporter_fixture.work(marc_exporter_fixture.collection3) + work.last_update_time = utc_now() - datetime.timedelta(days=50) marc_exporter_fixture.marc_file( collection=marc_exporter_fixture.collection3, library=marc_exporter_fixture.library2, + created=utc_now() - datetime.timedelta(days=45), ) marc.marc_export.delay().wait() - marc_export_collection.delay.assert_not_called() + + marc_export_collection.delay.assert_called_once_with( + collection_id=marc_exporter_fixture.collection3.id, + collection_name=marc_exporter_fixture.collection3.name, + start_time=ANY, + libraries=ANY, + ) class MarcExportCollectionFixture: