Skip to content

Commit 696e613

Browse files
feat: support include_deferred in pool sync for airflow 2.7.0 (#775)
* fix: add 'include_deferred' column to sync_pools script Signed-off-by: Einav Daniel <[email protected]> * fix: include_deferred implementation Signed-off-by: Mathew Wicks <[email protected]> --------- Signed-off-by: Einav Daniel <[email protected]> Signed-off-by: Mathew Wicks <[email protected]> Co-authored-by: Mathew Wicks <[email protected]>
1 parent 31dc335 commit 696e613

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

charts/airflow/docs/faq/dags/airflow-pools.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ airflow:
1414
- name: "pool_1"
1515
description: "example pool with 5 slots"
1616
slots: 5
17+
1718
- name: "pool_2"
1819
description: "example pool with 10 slots"
1920
slots: 10
21+
## if deferred tasks count towards the slot limit, requires airflow 2.7.0+ (default: false)
22+
#include_deferred: false
2023

2124
## if we create a Deployment to perpetually sync `airflow.pools`
2225
poolsUpdate: true

charts/airflow/templates/sync/_helpers/sync_pools.tpl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,23 @@ class PoolWrapper(object):
4747
name: str,
4848
description: str,
4949
slots: int,
50+
include_deferred: bool,
5051
policies: List[ScheduledPolicy],
5152
enable_policies: bool,
5253
):
5354
self.name = name
5455
self.description = description
5556
self.slots = slots
57+
self.include_deferred = include_deferred
5658
self.policies = policies
5759
self.enable_policies = enable_policies
5860

5961
def as_pool(self) -> Pool:
6062
pool = Pool()
6163
pool.pool = self.name
64+
# NOTE: include_deferred is only available in Airflow 2.7.0+
65+
if hasattr(Pool, "include_deferred"):
66+
pool.include_deferred = self.include_deferred
6267
if self._has_policies():
6368
most_recent_policy = self._most_recent_policy()
6469
pool.slots = most_recent_policy.slots
@@ -92,6 +97,15 @@ VAR__POOL_WRAPPERS = {
9297
{{ required "the `slots` in each `airflow.pools[]` must be int-type!" nil }}
9398
{{- end }}
9499
slots={{ (required "the `slots` in each `airflow.pools[]` must be non-empty!" .slots) }},
100+
{{- $include_deferred := dig "include_deferred" nil . }}
101+
{{- if not (or (typeIs "bool" $include_deferred) (eq $include_deferred nil)) }}
102+
{{ required "if specified, the `include_deferred` in each `airflow.pools[]` must be bool-type!" nil }}
103+
{{- end }}
104+
{{- if $include_deferred }}
105+
include_deferred=True,
106+
{{- else }}
107+
include_deferred=False,
108+
{{- end }}
95109
policies=[
96110
{{- range .policies }}
97111
ScheduledPolicy(
@@ -126,6 +140,7 @@ def compare_pools(p1: Pool, p2: Pool) -> bool:
126140
p1.pool == p1.pool
127141
and p1.description == p2.description
128142
and p1.slots == p2.slots
143+
and getattr(p1, "include_deferred", False) == getattr(p2, "include_deferred", False)
129144
)
130145

131146

@@ -152,6 +167,8 @@ def sync_pool(pool_wrapper: PoolWrapper) -> None:
152167
logging.info(f"Pool=`{p_name}` exists but has changed, updating...")
153168
p_old.description = p_new.description
154169
p_old.slots = p_new.slots
170+
if hasattr(Pool, "include_deferred"):
171+
p_old.include_deferred = p_new.include_deferred
155172
pool_updated = True
156173

157174
if pool_added:

charts/airflow/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ airflow:
162162
## - name: "pool_2"
163163
## description: "example pool with 2 cron policies"
164164
## slots: 0
165+
## ## if deferred tasks count towards the slot limit, requires airflow 2.7.0+ (default: false)
166+
## include_deferred: false
165167
## ## at each sync interval, the policy with the most recently past `recurrence` is applied
166168
## policies:
167169
## - name: "scale up at 7pm UTC"

0 commit comments

Comments
 (0)