Skip to content

Commit

Permalink
Fix triggerer query where limit is not supported in some MySQL ve…
Browse files Browse the repository at this point in the history
…rsion (apache#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.
  • Loading branch information
ephraimbuddy authored Aug 13, 2021
1 parent 4eff7a4 commit 55b9b70
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions airflow/models/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,10 @@ def assign_unassigned(cls, triggerer_id, capacity, session=None):
# 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()
2 changes: 1 addition & 1 deletion airflow/triggers/temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def run(self):
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():
Expand Down

0 comments on commit 55b9b70

Please sign in to comment.