Skip to content
Open
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
33 changes: 33 additions & 0 deletions src/palace/manager/api/admin/controller/catalog_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
)
from palace.manager.api.admin.form_data import ProcessFormData
from palace.manager.api.admin.problem_details import MULTIPLE_SERVICES_FOR_LIBRARY
from palace.manager.celery.tasks.marc import marc_export_reset
from palace.manager.integration.catalog.marc.exporter import MarcExporter
from palace.manager.integration.catalog.marc.settings import MarcExporterLibrarySettings
from palace.manager.integration.goals import Goals
from palace.manager.integration.settings import BaseSettings
from palace.manager.sqlalchemy.listeners import site_configuration_has_changed
Expand Down Expand Up @@ -87,19 +89,50 @@ def process_post(self) -> Response | ProblemDetail:
validated_settings = ProcessFormData.get_settings(settings_class, form_data)
catalog_service.settings_dict = validated_settings.model_dump()

# Capture current library settings so we can detect changes after the
# update.
old_library_settings: dict[int, MarcExporterLibrarySettings] = {
lc.library_id: impl_cls.library_settings_load(lc)
for lc in catalog_service.library_configurations
if lc.library_id is not None
}

# Update library settings
if libraries_data:
self.process_libraries(
catalog_service, libraries_data, impl_cls.library_settings_class()
)

# Find libraries whose settings actually changed. A MARC export reset
# is queued for each so that the next run produces a fresh full
# export along with a full-content delta.
reset_library_ids = [
lc.library_id
for lc in catalog_service.library_configurations
if lc.library_id is not None
and lc.library_id in old_library_settings
and impl_cls.library_settings_load(lc)
!= old_library_settings[lc.library_id]
]

# Trigger a site configuration change
site_configuration_has_changed(self._db)

except ProblemDetailException as e:
self._db.rollback()
return e.problem_detail

# Dispatch the resets before committing: a failed enqueue then rolls the
# settings change back, and a retried save re-queues the reset. The
# reverse order could commit the settings and then lose a reset, leaving
# delta-only consumers with stale records indefinitely. If the commit
# fails after dispatch, the cost is only a spurious reset: the files are
# regenerated from unchanged settings by the next scheduled export run.
if reset_library_ids:
for library_id in reset_library_ids:
marc_export_reset.delay(library_id)
Comment thread
greptile-apps[bot] marked this conversation as resolved.
self._db.commit()

return Response(str(catalog_service.id), response_code)

def process_delete(self, service_id: int) -> Response:
Expand Down
9 changes: 7 additions & 2 deletions src/palace/manager/api/controller/marc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from sqlalchemy.orm import Session

from palace.manager.api.util.flask import get_request_library
from palace.manager.integration.catalog.marc.exporter import MarcExporter
from palace.manager.integration.catalog.marc.exporter import MARC_EPOCH, MarcExporter
from palace.manager.service.integration_registry.catalog_services import (
CatalogServicesRegistry,
)
Expand Down Expand Up @@ -171,7 +171,12 @@ def download_page_body(self, session: Session, library: Library) -> str:
body += "<ul>"
for update in files.deltas:
update_url = self.storage_service.generate_url(update.key)
update_label = f"Updates from {update.since.strftime(time_format)} to {update.created.strftime(time_format)}"
# Avoid misleading label for full-content delta.
update_label = (
f"Full content as of {update.created.strftime(time_format)}"
if update.since == MARC_EPOCH
else f"Updates from {update.since.strftime(time_format)} to {update.created.strftime(time_format)}"
)
body += f'<li><a href="{update_url}">{update_label}</a></li>'
body += "</ul>"

Expand Down
Loading
Loading