|
53 | 53 | from airflow.typing_compat import Self
|
54 | 54 | from airflow.utils import timezone
|
55 | 55 | from airflow.utils.state import DagRunState, TaskInstanceState
|
| 56 | +from airflow.utils.types import DagRunType |
56 | 57 |
|
57 | 58 | if TYPE_CHECKING:
|
58 | 59 | from sqlalchemy.sql import ColumnElement, Select
|
@@ -528,6 +529,32 @@ def _transform_dag_run_states(states: Iterable[str] | None) -> list[DagRunState
|
528 | 529 | ),
|
529 | 530 | ]
|
530 | 531 |
|
| 532 | + |
| 533 | +def _transform_dag_run_types(types: list[str] | None) -> list[DagRunType | None] | None: |
| 534 | + try: |
| 535 | + if not types: |
| 536 | + return None |
| 537 | + return [None if run_type in ("none", None) else DagRunType(run_type) for run_type in types] |
| 538 | + except ValueError: |
| 539 | + raise HTTPException( |
| 540 | + status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, |
| 541 | + detail=f"Invalid value for run type. Valid values are {', '.join(DagRunType)}", |
| 542 | + ) |
| 543 | + |
| 544 | + |
| 545 | +QueryDagRunRunTypesFilter = Annotated[ |
| 546 | + FilterParam[list[str]], |
| 547 | + Depends( |
| 548 | + filter_param_factory( |
| 549 | + attribute=DagRun.run_type, |
| 550 | + _type=list[str], |
| 551 | + filter_option=FilterOptionEnum.ANY_EQUAL, |
| 552 | + default_factory=list, |
| 553 | + transform_callable=_transform_dag_run_types, |
| 554 | + ) |
| 555 | + ), |
| 556 | +] |
| 557 | + |
531 | 558 | # DAGTags
|
532 | 559 | QueryDagTagPatternSearch = Annotated[
|
533 | 560 | _SearchParam, Depends(search_param_factory(DagTag.name, "tag_name_pattern"))
|
@@ -601,3 +628,28 @@ def _transform_ti_states(states: list[str] | None) -> list[TaskInstanceState | N
|
601 | 628 | QueryVariableKeyPatternSearch = Annotated[
|
602 | 629 | _SearchParam, Depends(search_param_factory(Variable.key, "variable_key_pattern"))
|
603 | 630 | ]
|
| 631 | + |
| 632 | + |
| 633 | +# UI Shared |
| 634 | +def _optional_boolean(value: bool | None) -> bool | None: |
| 635 | + return value if value is not None else False |
| 636 | + |
| 637 | + |
| 638 | +QueryIncludeUpstream = Annotated[Union[bool], AfterValidator(_optional_boolean)] |
| 639 | +QueryIncludeDownstream = Annotated[Union[bool], AfterValidator(_optional_boolean)] |
| 640 | + |
| 641 | +state_priority: list[None | TaskInstanceState] = [ |
| 642 | + TaskInstanceState.FAILED, |
| 643 | + TaskInstanceState.UPSTREAM_FAILED, |
| 644 | + TaskInstanceState.UP_FOR_RETRY, |
| 645 | + TaskInstanceState.UP_FOR_RESCHEDULE, |
| 646 | + TaskInstanceState.QUEUED, |
| 647 | + TaskInstanceState.SCHEDULED, |
| 648 | + TaskInstanceState.DEFERRED, |
| 649 | + TaskInstanceState.RUNNING, |
| 650 | + TaskInstanceState.RESTARTING, |
| 651 | + None, |
| 652 | + TaskInstanceState.SUCCESS, |
| 653 | + TaskInstanceState.SKIPPED, |
| 654 | + TaskInstanceState.REMOVED, |
| 655 | +] |
0 commit comments