fix: clarify pending admission failure outcome (#101)
This commit is contained in:
+13
-4
@@ -428,10 +428,15 @@ def _is_store_or_invariant_failure(exc: Exception) -> bool:
|
|||||||
) or isinstance(exc, InvariantViolationError)
|
) or isinstance(exc, InvariantViolationError)
|
||||||
|
|
||||||
|
|
||||||
def _pending_capacity_error(reason: str) -> RuntimeError:
|
def _pending_capacity_error(
|
||||||
|
reason: str,
|
||||||
|
*,
|
||||||
|
acquisition_skipped: bool = False,
|
||||||
|
) -> RuntimeError:
|
||||||
|
outcome = "; no new observation acquired" if acquisition_skipped else ""
|
||||||
return RuntimeError(
|
return RuntimeError(
|
||||||
"pending publication capacity full "
|
"pending publication capacity full "
|
||||||
f"({PENDING_PUBLICATION_LIMIT} observations); no new observation acquired; "
|
f"({PENDING_PUBLICATION_LIMIT} observations){outcome}; "
|
||||||
f"{reason}"
|
f"{reason}"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -469,12 +474,16 @@ def _recover_pending_for_admission(conn: sqlite3.Connection) -> int:
|
|||||||
raise failure.cause
|
raise failure.cause
|
||||||
if pending_count >= PENDING_PUBLICATION_LIMIT:
|
if pending_count >= PENDING_PUBLICATION_LIMIT:
|
||||||
raise _pending_capacity_error(
|
raise _pending_capacity_error(
|
||||||
f"recovery failed: {failure.cause}"
|
f"recovery failed: {failure.cause}",
|
||||||
|
acquisition_skipped=True,
|
||||||
) from failure.cause
|
) from failure.cause
|
||||||
return failure.published_count
|
return failure.published_count
|
||||||
|
|
||||||
if _pending_count(conn) >= PENDING_PUBLICATION_LIMIT:
|
if _pending_count(conn) >= PENDING_PUBLICATION_LIMIT:
|
||||||
raise _pending_capacity_error("recovery left the queue full")
|
raise _pending_capacity_error(
|
||||||
|
"recovery left the queue full",
|
||||||
|
acquisition_skipped=True,
|
||||||
|
)
|
||||||
return recovered
|
return recovered
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -139,6 +139,7 @@ def test_partial_recovery_frees_admission_and_keeps_pending_order(
|
|||||||
)
|
)
|
||||||
assert partial["ok"] is False
|
assert partial["ok"] is False
|
||||||
assert acquired is True, partial
|
assert acquired is True, partial
|
||||||
|
assert "no new observation acquired" not in partial["error"]
|
||||||
|
|
||||||
with sqlite3.connect(store_path) as conn:
|
with sqlite3.connect(store_path) as conn:
|
||||||
assert conn.execute(
|
assert conn.execute(
|
||||||
|
|||||||
Reference in New Issue
Block a user