jscheffl commented on code in PR #42048: URL: https://github.com/apache/airflow/pull/42048#discussion_r1765723006
########## airflow/providers/edge/executors/edge_executor.py: ########## @@ -0,0 +1,175 @@ +# 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. + +from __future__ import annotations + +from datetime import datetime, timedelta +from typing import TYPE_CHECKING, Any + +from sqlalchemy import delete + +from airflow.cli.cli_config import GroupCommand +from airflow.configuration import conf +from airflow.executors.base_executor import BaseExecutor +from airflow.models.abstractoperator import DEFAULT_QUEUE +from airflow.models.taskinstance import TaskInstanceState +from airflow.providers.edge.models.edge_job import EdgeJobModel +from airflow.providers.edge.models.edge_logs import EdgeLogsModel +from airflow.providers.edge.models.edge_worker import EdgeWorkerModel +from airflow.utils.db import DBLocks, create_global_lock +from airflow.utils.session import NEW_SESSION, provide_session + +if TYPE_CHECKING: + import argparse + + from sqlalchemy.orm import Session + + from airflow.executors.base_executor import CommandType + from airflow.models.taskinstance import TaskInstance + from airflow.models.taskinstancekey import TaskInstanceKey + +PARALLELISM: int = conf.getint("core", "PARALLELISM") + + +class EdgeExecutor(BaseExecutor): + """Implementation of the EdgeExecutor to distribute work to Edge Workers via HTTP.""" + + def __init__(self, parallelism: int = PARALLELISM): + super().__init__(parallelism=parallelism) + self.last_reported_state: dict[TaskInstanceKey, TaskInstanceState] = {} + + @provide_session + def start(self, session: Session = NEW_SESSION): + """If EdgeExecutor provider is loaded first time, ensure table exists.""" + with create_global_lock(session=session, lock=DBLocks.MIGRATIONS): + engine = session.get_bind().engine + EdgeJobModel.metadata.create_all(engine) + EdgeLogsModel.metadata.create_all(engine) + EdgeWorkerModel.metadata.create_all(engine) + + @provide_session + def execute_async( + self, + key: TaskInstanceKey, + command: CommandType, + queue: str | None = None, + executor_config: Any | None = None, + session: Session = NEW_SESSION, + ) -> None: + """Execute asynchronously.""" + self.validate_airflow_tasks_run_command(command) + session.add( Review Comment: Yes. Thanks for the remarks. I did not intend to make the implementation final or "hide" tech debt. It is marked as MVP to provide a first function and the aim is to incrementally improve. This means in functionality, reliability and performance. My intend after MVP is to use it and step by step improve open items based on the documented backlog - by myself, my team - and if somebody else is using also happy to receive contributions from the community. Just added some notes to the RST to make clear that performance tuning is something that will/must be added post MVP. So no load tests have been made until now. And also I acknowledge that there was a lot of performance consideration in current Hybrid Executor implementation. As well as in Non-Hybrid K8s Executor. Was also not aware (before the summit) about the async-complexity - But also in case of K8s you have a lot of remote calls on the API to raise and follow started workload. And assuming a many users expect scalability to scale on K8s/Celery as of 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]
