Skip to content

Commit 324dcf7

Browse files
vitorvitor
authored andcommitted
add tag and retry policy
1 parent babfe81 commit 324dcf7

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

config/airflow_local_settings.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from airflow.exceptions import AirflowClusterPolicyViolation
77

88
ALLOWED_OWNERS = "team_contacts"
9+
ALLOWED_TAGS = "airflow_tags_allowed_list"
910

1011

1112
def dag_policy(dag):
@@ -26,6 +27,11 @@ def dag_policy(dag):
2627
else dag.dagrun_timeout
2728
)
2829

30+
# Set tasks retries max to 3
31+
retries = dag.default_args.get("retries", False)
32+
if retries and retries > 3:
33+
dag.default_args["retries"] = 3
34+
2935
# Check if owner exists
3036
owner = dag.default_args.get("owner", "")
3137
owner_dag_list = owner.split(",")
@@ -49,8 +55,18 @@ def dag_policy(dag):
4955
)
5056

5157
# Check if dag has tags
52-
if not dag.tags:
58+
tags = dag.tags
59+
if not tags:
5360
raise AirflowClusterPolicyViolation(
5461
f"DAG has no tags. At least one tag required."
5562
)
63+
64+
# Check if tag is allowed
65+
tag_allowed_list = yaml.safe_load(Variable.get(ALLOWED_TAGS))
66+
if not all(item in tag_allowed_list for item in tags):
67+
raise AirflowClusterPolicyViolation(
68+
f"One of tags(s) {tags} not in Airflow Variable {ALLOWED_TAGS}"
69+
)
70+
71+
5672
# EOF

0 commit comments

Comments
 (0)