You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2019/12/04 12:09:17 UTC

[GitHub] [airflow] potiuk commented on a change in pull request #6725: [AIRFLOW-6157] Support for multiple executors

potiuk commented on a change in pull request #6725: [AIRFLOW-6157] Support for multiple executors
URL: https://github.com/apache/airflow/pull/6725#discussion_r353706504
 
 

 ##########
 File path: airflow/executors/multiple_executors.py
 ##########
 @@ -0,0 +1,117 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Multiple  executor."""
+from itertools import chain
+from typing import Any, Dict, Iterable, Optional, Set
+
+from airflow.executors.base_executor import BaseExecutor, BaseExecutorProtocol, CommandType
+from airflow.models import TaskInstance
+from airflow.models.taskinstance import SimpleTaskInstance, TaskInstanceKeyType
+
+
+class MultipleExecutors(BaseExecutorProtocol):
+    """
+    This executor can run multiple executors under the hood.
+    """
+    def __init__(self, main_executor: BaseExecutor, additional_executors_dict: Dict[str, BaseExecutor]):
+        super().__init__()
+        self.main_executor = main_executor
+        self.additional_executors_dict = additional_executors_dict
+        self.executor_set: Set[BaseExecutor] = set(additional_executors_dict.values())
+        self.executor_set.add(main_executor)
+        self.log.info("Multiple executor")
+        self.log.info("Main executor %s", str(main_executor))
+        self.log.info("Additional executor dict %s", str(self.additional_executors_dict))
+        self.log.info("Executor set %s", str(self.executor_set))
+
+    def _get_executor_for_queue(self, queue: Optional[str]) -> BaseExecutor:
+        executor = None
+        if queue:
+            executor = self.additional_executors_dict.get(queue)
+        return self.main_executor if not executor else executor
+
+    def start(self):
+        for executor in self.executor_set:
+            executor.start()
+
+    def has_task(self, task_instance: TaskInstance) -> bool:
+        executor = self._get_executor_for_queue(task_instance.queue)
+        return executor.has_task(task_instance=task_instance)
+
+    def sync(self) -> None:
+        for executor in self.executor_set:
+            executor.sync()
 
 Review comment:
   sure. We can set variable and make single return :)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services