Skip to content

Commit

Permalink
Another update
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathangreen committed Oct 29, 2024
1 parent 851fca8 commit 058529d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
26 changes: 20 additions & 6 deletions src/palace/manager/celery/tasks/marc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 12 additions & 3 deletions tests/manager/celery/tasks/test_marc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 058529d

Please sign in to comment.