Skip to content

Commit b2bee2e

Browse files
committed
Implement find_breached_clocks() function
1 parent 335298b commit b2bee2e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

policylens/apps/claims/sla.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,21 @@ def ensure_sla_clock_exists(*, claim: Claim) -> SlaClock:
7979
claim=claim,
8080
started_at=anchor,
8181
due_at=due_at,
82-
)
82+
)
83+
84+
85+
def find_breached_clocks(*, now) -> Iterable[SlaClock]:
86+
"""Return clocks that are currently breached and not yet marked.
87+
88+
Args:
89+
now: Current time.
90+
91+
Returns:
92+
Iterable of SlaClock objects.
93+
"""
94+
return (
95+
SlaClock.objects.select_related("claim")
96+
.filter(breached_at__isnull=True, due_at__isnull=False, due_at__lt=now)
97+
.exclude(claim__status=Claim.Status.DECIDED)
98+
.order_by("due_at")
99+
)

0 commit comments

Comments
 (0)