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
14 changes: 7 additions & 7 deletions airflow/executors/celery_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from airflow.configuration import conf
from airflow.exceptions import AirflowException, AirflowTaskTimeout
from airflow.executors.base_executor import BaseExecutor, CommandType, EventBufferValueType
from airflow.models.taskinstance import SimpleTaskInstance, TaskInstance, TaskInstanceKey
from airflow.models.taskinstance import TaskInstance, TaskInstanceKey
from airflow.stats import Stats
from airflow.utils.log.logging_mixin import LoggingMixin
from airflow.utils.net import get_hostname
Expand Down Expand Up @@ -154,15 +154,15 @@ def __init__(self, exception: Exception, exception_traceback: str):


# Task instance that is sent over Celery queues
# TaskInstanceKey, SimpleTaskInstance, Command, queue_name, CallableTask
TaskInstanceInCelery = Tuple[TaskInstanceKey, SimpleTaskInstance, CommandType, Optional[str], Task]
# TaskInstanceKey, Command, queue_name, CallableTask
TaskInstanceInCelery = Tuple[TaskInstanceKey, CommandType, Optional[str], Task]


def send_task_to_executor(
task_tuple: TaskInstanceInCelery,
) -> Tuple[TaskInstanceKey, CommandType, Union[AsyncResult, ExceptionWithTraceback]]:
"""Sends task to executor."""
key, _, command, queue, task_to_run = task_tuple
key, command, queue, task_to_run = task_tuple
try:
with timeout(seconds=OPERATION_TIMEOUT):
result = task_to_run.apply_async(args=[command], queue=queue)
Expand Down Expand Up @@ -250,8 +250,8 @@ def trigger_tasks(self, open_slots: int) -> None:
task_tuples_to_send: List[TaskInstanceInCelery] = []

for _ in range(min(open_slots, len(self.queued_tasks))):
key, (command, _, queue, simple_ti) = sorted_queue.pop(0)
task_tuple = (key, simple_ti, command, queue, execute_command)
key, (command, _, queue, _) = sorted_queue.pop(0)
task_tuple = (key, command, queue, execute_command)
task_tuples_to_send.append(task_tuple)
if key not in self.task_publish_retries:
self.task_publish_retries[key] = 1
Expand All @@ -260,7 +260,7 @@ def trigger_tasks(self, open_slots: int) -> None:
self._process_tasks(task_tuples_to_send)

def _process_tasks(self, task_tuples_to_send: List[TaskInstanceInCelery]) -> None:
first_task = next(t[4] for t in task_tuples_to_send)
first_task = next(t[3] for t in task_tuples_to_send)

# Celery state queries will stuck if we do not use one same backend
# for all tasks.
Expand Down
6 changes: 2 additions & 4 deletions tests/executors/test_celery_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,21 @@ def fake_execute_command(command):
task_tuples_to_send = [
(
('success', 'fake_simple_ti', execute_date, 0),
None,
success_command,
celery_executor.celery_configuration['task_default_queue'],
celery_executor.execute_command,
),
(
('fail', 'fake_simple_ti', execute_date, 0),
None,
fail_command,
celery_executor.celery_configuration['task_default_queue'],
celery_executor.execute_command,
),
]

# "Enqueue" them. We don't have a real SimpleTaskInstance, so directly edit the dict
for (key, simple_ti, command, queue, task) in task_tuples_to_send:
executor.queued_tasks[key] = (command, 1, queue, simple_ti)
for (key, command, queue, task) in task_tuples_to_send:
executor.queued_tasks[key] = (command, 1, queue, None)
executor.task_publish_retries[key] = 1

executor._process_tasks(task_tuples_to_send)
Expand Down