Skip to content

Commit

Permalink
Pp 1755 fix overdrive sweep transaction errors (#2091)
Browse files Browse the repository at this point in the history
* [PP-1755] Fix overdrive format sweep transaction errors.

* [PP-1755] Fix overdrive format sweep transaction errors.
  • Loading branch information
dbernstein authored Oct 1, 2024
1 parent ebcddca commit b90936f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/palace/manager/core/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import traceback
from typing import TYPE_CHECKING

from sqlalchemy.exc import InvalidRequestError
from sqlalchemy.orm import defer
from sqlalchemy.orm.exc import ObjectDeletedError, StaleDataError
from sqlalchemy.sql.expression import and_, or_
Expand Down Expand Up @@ -516,6 +517,7 @@ def run_once(self, *ignore):
retry=(
retry_if_exception_type(StaleDataError)
| retry_if_exception_type(ObjectDeletedError)
| retry_if_exception_type(InvalidRequestError)
),
stop=stop_after_attempt(MAXIMUM_BATCH_RETRIES),
wait=wait_exponential(multiplier=1, min=1, max=60),
Expand Down
5 changes: 4 additions & 1 deletion tests/manager/core/test_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from unittest.mock import MagicMock

import pytest
from sqlalchemy.exc import InvalidRequestError
from sqlalchemy.orm.exc import ObjectDeletedError, StaleDataError

from palace.manager.api.bibliotheca import BibliothecaAPI
Expand Down Expand Up @@ -700,14 +701,16 @@ def process_item(self, item):
raise StaleDataError("stale data")
elif self.process_item_invocation_count == 2:
raise ObjectDeletedError({}, "object deleted")
elif self.process_item_invocation_count == 3:
raise InvalidRequestError("invalid request")
else:
super().process_item(item)

monitor = FailOnFirstTwoCallsSucceedOnThird(db.session)
timestamp = monitor.timestamp()
monitor.run()
# we expect that process should have been called 3 times total
assert monitor.process_item_invocation_count == 3
assert monitor.process_item_invocation_count == 4
# there shouldn't be an exception saved since it ultimately succeeded.
assert timestamp.exception is None
assert "Records processed: 1." == timestamp.achievements
Expand Down

0 comments on commit b90936f

Please sign in to comment.