Skip to content

Commit 478c26c

Browse files
committed
refactor(api): type workflow run related counts with RelatedCountsDict TypedDict
1 parent 4e1d060 commit 478c26c

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

api/services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import random
44
import time
55
from collections.abc import Iterable, Sequence
6-
from typing import TYPE_CHECKING
6+
from typing import TYPE_CHECKING, TypedDict
77

88
import click
99
from sqlalchemy.orm import Session, sessionmaker
@@ -145,7 +145,7 @@ def record_batch(
145145
targeted_runs: int,
146146
skipped_runs: int,
147147
deleted_runs: int,
148-
related_counts: dict[str, int] | None,
148+
related_counts: RelatedCountsDict | None,
149149
related_action: str | None,
150150
batch_duration_seconds: float,
151151
) -> None:
@@ -173,6 +173,15 @@ def record_completion(self, *, status: str, job_duration_seconds: float) -> None
173173
self._record(self._job_duration_seconds, job_duration_seconds, attributes)
174174

175175

176+
class RelatedCountsDict(TypedDict):
177+
node_executions: int
178+
offloads: int
179+
app_logs: int
180+
trigger_logs: int
181+
pauses: int
182+
pause_reasons: int
183+
184+
176185
class WorkflowRunCleanup:
177186
def __init__(
178187
self,
@@ -506,7 +515,7 @@ def _count_trigger_logs(self, session: Session, run_ids: Sequence[str]) -> int:
506515
return trigger_repo.count_by_run_ids(run_ids)
507516

508517
@staticmethod
509-
def _empty_related_counts() -> dict[str, int]:
518+
def _empty_related_counts() -> RelatedCountsDict:
510519
return {
511520
"node_executions": 0,
512521
"offloads": 0,
@@ -517,7 +526,7 @@ def _empty_related_counts() -> dict[str, int]:
517526
}
518527

519528
@staticmethod
520-
def _format_related_counts(counts: dict[str, int]) -> str:
529+
def _format_related_counts(counts: RelatedCountsDict) -> str:
521530
return (
522531
f"node_executions {counts['node_executions']}, "
523532
f"offloads {counts['offloads']}, "

0 commit comments

Comments
 (0)