refactor(diagnostics): use model functions and clean up code

- Move all internal/local imports to top-level
- Remove unnecessary try-except blocks that just re-raise
- Replace direct Prisma count queries with get_graph_executions_count
- Add updated_time_gte/lte filter to get_graph_executions_count for
  querying failed/completed executions by update time
- Fix N+1 query in cleanup_orphaned_schedules_bulk by fetching all
  schedules once before the loop
- Extract SYSTEM_JOB_IDS constant to module level to avoid duplication

Co-authored-by: Nicholas Tindle <ntindle@users.noreply.github.com>
This commit is contained in:
claude[bot]
2026-02-05 05:42:07 +00:00
parent 265295606b
commit 81a8e6f558
2 changed files with 692 additions and 809 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -546,6 +546,8 @@ async def get_graph_executions_count(
created_time_lte: Optional[datetime] = None,
started_time_gte: Optional[datetime] = None,
started_time_lte: Optional[datetime] = None,
updated_time_gte: Optional[datetime] = None,
updated_time_lte: Optional[datetime] = None,
) -> int:
"""
Get count of graph executions with optional filters.
@@ -558,6 +560,8 @@ async def get_graph_executions_count(
created_time_lte: Optional maximum creation time
started_time_gte: Optional minimum start time (when execution started running)
started_time_lte: Optional maximum start time (when execution started running)
updated_time_gte: Optional minimum update time
updated_time_lte: Optional maximum update time
Returns:
Count of matching graph executions
@@ -584,6 +588,12 @@ async def get_graph_executions_count(
"lte": started_time_lte or datetime.max.replace(tzinfo=timezone.utc),
}
if updated_time_gte or updated_time_lte:
where_filter["updatedAt"] = {
"gte": updated_time_gte or datetime.min.replace(tzinfo=timezone.utc),
"lte": updated_time_lte or datetime.max.replace(tzinfo=timezone.utc),
}
if statuses:
where_filter["OR"] = [{"executionStatus": status} for status in statuses]