You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ka...@apache.org on 2021/08/13 18:44:39 UTC
[airflow] branch main updated: Fix ``triggerer`` query where limit
is not supported in some MySQL version (#17601)
This is an automated email from the ASF dual-hosted git repository.
kaxilnaik pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 55b9b70 Fix ``triggerer`` query where limit is not supported in some MySQL version (#17601)
55b9b70 is described below
commit 55b9b70cf2e015478b949067c9bae38f0cc142cd
Author: Ephraim Anierobi <sp...@gmail.com>
AuthorDate: Fri Aug 13 19:44:27 2021 +0100
Fix ``triggerer`` query where limit is not supported in some MySQL version (#17601)
This PR fixes the triggerrer query where limit is not supported in some DB versions and also fixed the issue where total_hours was used on a timedelta.
---
airflow/models/trigger.py | 8 +++-----
airflow/triggers/temporal.py | 2 +-
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/airflow/models/trigger.py b/airflow/models/trigger.py
index a49d6c8..5749589 100644
--- a/airflow/models/trigger.py
+++ b/airflow/models/trigger.py
@@ -184,12 +184,10 @@ class Trigger(Base):
# Find triggers who do NOT have an alive triggerer_id, and then assign
# up to `capacity` of those to us.
trigger_ids_query = (
- session.query(cls.id)
- .filter(cls.triggerer_id.notin_(alive_triggerer_ids))
- .limit(capacity)
- .subquery()
+ session.query(cls.id).filter(cls.triggerer_id.notin_(alive_triggerer_ids)).limit(capacity).all()
)
- session.query(cls).filter(cls.id.in_(trigger_ids_query)).update(
+ session.query(cls).filter(cls.id.in_([i.id for i in trigger_ids_query])).update(
{cls.triggerer_id: triggerer_id},
synchronize_session=False,
)
+ session.commit()
diff --git a/airflow/triggers/temporal.py b/airflow/triggers/temporal.py
index c27f6e5..26685e3 100644
--- a/airflow/triggers/temporal.py
+++ b/airflow/triggers/temporal.py
@@ -54,7 +54,7 @@ class DateTimeTrigger(BaseTrigger):
unexpectedly, or handles a DST change poorly.
"""
# Sleep an hour at a time while it's more than 2 hours away
- while (self.moment - timezone.utcnow()).total_hours() > 2:
+ while (self.moment - timezone.utcnow()).total_seconds() > 2 * 3600:
await asyncio.sleep(3600)
# Sleep a second at a time otherwise
while self.moment > timezone.utcnow():