-
Notifications
You must be signed in to change notification settings - Fork 16.9k
Expand file tree
/
Copy pathtypes.py
More file actions
76 lines (58 loc) · 2.51 KB
/
types.py
File metadata and controls
76 lines (58 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from __future__ import annotations
import enum
from typing import TYPE_CHECKING, TypedDict
import airflow.sdk.definitions._internal.types
if TYPE_CHECKING:
from airflow.typing_compat import TypeAlias
ArgNotSet: TypeAlias = airflow.sdk.definitions._internal.types.ArgNotSet
NOTSET = airflow.sdk.definitions._internal.types.NOTSET
class DagRunType(str, enum.Enum):
"""Class with DagRun types."""
BACKFILL_JOB = "backfill"
SCHEDULED = "scheduled"
MANUAL = "manual"
ASSET_TRIGGERED = "asset_triggered"
def __str__(self) -> str:
return self.value
def generate_run_id(self, *, suffix: str) -> str:
"""
Generate a string for DagRun based on suffix string.
:param suffix: Generate run_id from suffix.
"""
return f"{self}__{suffix}"
@staticmethod
def from_run_id(run_id: str) -> DagRunType:
"""Resolve DagRun type from run_id."""
for run_type in DagRunType:
if run_id and run_id.startswith(f"{run_type.value}__"):
return run_type
return DagRunType.MANUAL
class EdgeInfoType(TypedDict):
"""Extra metadata that the DAG can store about an edge, usually generated from an EdgeModifier."""
label: str | None
class DagRunTriggeredByType(enum.Enum):
"""Class with TriggeredBy types for DagRun."""
CLI = "cli" # for the trigger subcommand of the CLI: airflow dags trigger
OPERATOR = "operator" # for the TriggerDagRunOperator
REST_API = "rest_api" # for triggering the DAG via RESTful API
UI = "ui" # for clicking the `Trigger DAG` button
TEST = "test" # for dag.test()
TIMETABLE = "timetable" # for timetable based triggering
ASSET = "asset" # for asset_triggered run type
BACKFILL = "backfill"