georborodin commented on a change in pull request #18189:
URL: https://github.com/apache/airflow/pull/18189#discussion_r707082577



##########
File path: airflow/executors/executor_loader.py
##########
@@ -77,14 +77,36 @@ def load_executor(cls, executor_name: str) -> BaseExecutor:
         """
         if executor_name == CELERY_KUBERNETES_EXECUTOR:
             return cls.__load_celery_kubernetes_executor()
+        try:
+            executor_cls, import_source = 
cls.import_executor_cls(executor_name)
+            log.debug(
+                "Loading executor %s from %s", executor_name, 
import_source.replace("custom", "custom path")
+            )
+        except ImportError as e:
+            log.error(e)
+            raise AirflowConfigException(
+                f'The module/attribute could not be loaded. Please check 
"executor" key in "core" section. '
+                f'Current value: "{executor_name}".'
+            )
+        log.info("Loaded executor: %s", executor_name)
+
+        return executor_cls()
+
+    @classmethod
+    def import_executor_cls(cls, executor_name: str) -> 
Tuple[Type[BaseExecutor], str]:
+        """
+        Imports the executor class.
+
+        Supports the same formats as ExecutorLoader.load_executor.
 
+        :return: a tuple with executor class via executor_name and
+        import source (i.e. "core", "plugin", "custom)
+        """
         if executor_name in cls.executors:
-            log.debug("Loading core executor: %s", executor_name)
-            return import_string(cls.executors[executor_name])()
-        # If the executor name looks like "plugin executor path" then try to 
load plugins.
+            return import_string(cls.executors[executor_name]), "core"

Review comment:
       That is definitely better than plain strings :) 
   Will add it later today




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to