Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions airflow/executors/base_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,25 @@ def heartbeat(self) -> None:
self.log.debug("Calling the %s sync method", self.__class__)
self.sync()

def trigger_tasks(self, open_slots: int) -> None:
def order_queued_tasks_by_priority(self) -> List[Tuple[TaskInstanceKeyType, QueuedTaskInstanceType]]:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about making this a property?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could make it harder to understand the code. Note that a loop is used below that iterates over the result of this function, but at the same time modifies self.queued_tasks). If we create a property here, it will be difficult to see that property and self.queued_task are related.

"""
Triggers tasks
Orders the queued tasks by priority.

:param open_slots: Number of open slots
:return: List of tuples from the queued_tasks according to the priority.
"""
sorted_queue = sorted(
return sorted(
[(k, v) for k, v in self.queued_tasks.items()], # pylint: disable=unnecessary-comprehension
key=lambda x: x[1][1],
reverse=True)

def trigger_tasks(self, open_slots: int) -> None:
"""
Triggers tasks

:param open_slots: Number of open slots
"""
sorted_queue = self.order_queued_tasks_by_priority()

for _ in range(min((open_slots, len(self.queued_tasks)))):
key, (command, _, _, simple_ti) = sorted_queue.pop(0)
self.queued_tasks.pop(key)
Expand Down
13 changes: 1 addition & 12 deletions airflow/executors/celery_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from airflow.config_templates.default_celery import DEFAULT_CELERY_CONFIG
from airflow.configuration import conf
from airflow.exceptions import AirflowException
from airflow.executors.base_executor import BaseExecutor, CommandType, QueuedTaskInstanceType
from airflow.executors.base_executor import BaseExecutor, CommandType
from airflow.models.taskinstance import SimpleTaskInstance, TaskInstanceKeyType, TaskInstanceStateType
from airflow.utils.log.logging_mixin import LoggingMixin
from airflow.utils.module_loading import import_string
Expand Down Expand Up @@ -234,17 +234,6 @@ def trigger_tasks(self, open_slots: int) -> None:
self.tasks[key] = result
self.last_state[key] = celery_states.PENDING

def order_queued_tasks_by_priority(self) -> List[Tuple[TaskInstanceKeyType, QueuedTaskInstanceType]]:
"""
Orders the queued tasks by priority.

:return: List of tuples from the queued_tasks according to the priority.
"""
return sorted(
[(k, v) for k, v in self.queued_tasks.items()], # pylint: disable=unnecessary-comprehension
key=lambda x: x[1][1],
reverse=True)

def sync(self) -> None:
num_processes = min(len(self.tasks), self._sync_parallelism)
if num_processes == 0:
Expand Down