Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathangreen committed Oct 16, 2024
1 parent 4e69c0c commit 7bd03c5
Show file tree
Hide file tree
Showing 15 changed files with 727 additions and 1,144 deletions.
6 changes: 0 additions & 6 deletions bin/opds2_odl_hold_reaper

This file was deleted.

1 change: 0 additions & 1 deletion docker/services/cron/cron.d/circulation
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ HOME=/var/www/circulation
# OPDS 2.x + ODL import
#
45 * * * * root bin/run opds2_odl_import_monitor >> /var/log/cron.log 2>&1
0 */8 * * * root bin/run opds2_odl_hold_reaper >> /var/log/cron.log 2>&1

# SAML
#
Expand Down
1 change: 0 additions & 1 deletion src/palace/manager/api/circulation_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ def setup_one_time_controllers(self):
self.version = ApplicationVersionController()
self.odl_notification_controller = ODLNotificationController(
self._db,
self,
self.services.integration_registry.license_providers(),
)
self.patron_auth_token = PatronAuthTokenController(self)
Expand Down
23 changes: 7 additions & 16 deletions src/palace/manager/api/controller/odl_notification.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import annotations

from typing import TYPE_CHECKING

import flask
from flask import Response
from flask_babel import lazy_gettext as _
Expand All @@ -18,15 +16,12 @@
from palace.manager.service.integration_registry.license_providers import (
LicenseProvidersRegistry,
)
from palace.manager.sqlalchemy.model.library import Library
from palace.manager.sqlalchemy.model.patron import Loan
from palace.manager.sqlalchemy.util import get_one
from palace.manager.util.datetime_helpers import utc_now
from palace.manager.util.log import LoggerMixin
from palace.manager.util.problem_detail import ProblemDetail

if TYPE_CHECKING:
from palace.manager.api.circulation_manager import CirculationManager


class ODLNotificationController(LoggerMixin):
"""Receive notifications from an ODL distributor when the
Expand All @@ -36,20 +31,12 @@ class ODLNotificationController(LoggerMixin):
def __init__(
self,
db: Session,
manager: CirculationManager,
registry: LicenseProvidersRegistry,
) -> None:
self.db = db
self.manager = manager
self.registry = registry

def get_api(self, library: Library, loan: Loan) -> OPDS2WithODLApi:
return self.manager.circulation_apis[library.id].api_for_license_pool( # type: ignore[no-any-return]
loan.license_pool
)

def notify(self, loan_id: int) -> Response | ProblemDetail:
library = flask.request.library # type: ignore[attr-defined]
status_doc_json = flask.request.data
loan = get_one(self.db, Loan, id=loan_id)

Expand All @@ -75,7 +62,11 @@ def notify(self, loan_id: int) -> Response | ProblemDetail:
):
return INVALID_LOAN_FOR_ODL_NOTIFICATION

api = self.get_api(library, loan)
api.update_loan(loan, status_doc)
# TODO: This should really just trigger a celery task to do an availabilty sync on the
# license, since this is flagging that we might be out of sync with the distributor.
# Once we move the OPDS2WithODL scripts to celery this should be possible.
# For now we just mark the loan as expired.
if not status_doc.active:
loan.end = utc_now()

return Response(status=204)
Loading

0 comments on commit 7bd03c5

Please sign in to comment.