fix: close broker uncertainty audit gaps
This commit is contained in:
@@ -15,10 +15,11 @@ from __future__ import annotations
|
||||
from dataclasses import replace
|
||||
from datetime import datetime, timezone
|
||||
from decimal import Decimal
|
||||
from typing import Any, Optional
|
||||
from typing import Any, Callable, Optional
|
||||
from uuid import UUID
|
||||
|
||||
from trex_core.domain.slot.errors import (
|
||||
SlotAdmissionRejectedError,
|
||||
SlotNotFoundError,
|
||||
SlotStateMismatchError,
|
||||
SlotTransitionError,
|
||||
@@ -87,6 +88,7 @@ class SlotService:
|
||||
slippage_pct: Optional[float] = None,
|
||||
venue: Optional[str] = None,
|
||||
extra: Optional[dict[str, Any]] = None,
|
||||
precondition: Optional[Callable[[Slot], Optional[str]]] = None,
|
||||
) -> Slot:
|
||||
"""Transition slot from one state to another atomically.
|
||||
|
||||
@@ -116,6 +118,10 @@ class SlotService:
|
||||
f"slot {slot_id} current state {slot.status.value} "
|
||||
f"!= requested from_state {from_state.value}"
|
||||
)
|
||||
if precondition is not None:
|
||||
rejection_reason = precondition(slot)
|
||||
if rejection_reason is not None:
|
||||
raise SlotAdmissionRejectedError(rejection_reason)
|
||||
|
||||
updated = self._apply_transition_fields(
|
||||
slot,
|
||||
|
||||
Reference in New Issue
Block a user