amoghrajesh commented on code in PR #51076:
URL: https://github.com/apache/airflow/pull/51076#discussion_r2108337061


##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/dags.py:
##########
@@ -0,0 +1,60 @@
+# 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
+
+import logging
+
+from fastapi import APIRouter, HTTPException, Query, status
+
+from airflow.api_fastapi.common.db.common import SessionDep
+from airflow.dag_processing.collection import update_dag_parsing_results_in_db
+from airflow.dag_processing.processor import DagFileParsingResult
+
+
+router = APIRouter()
+
+
+log = logging.getLogger(__name__)
+
+
[email protected](

Review Comment:
   Its more like a patch request? You are updating "something" in a dag.



##########
airflow-core/src/airflow/config_templates/config.yml:
##########
@@ -2479,3 +2479,12 @@ dag_processor:
       type: integer
       example: ~
       default: "10"
+    use_api_for_updating_dags:
+      description: |
+        Whether to use the API to update the database with the parsed DAGs.
+        If set to ``True``, the DAG processor will use the API to update the 
database with the parsed DAGs.
+        If set to ``False``, the DAG processor will use the database directly 
to update the parsed DAGs.
+      version_added: 3.2.0

Review Comment:
   3.2.0 is planned late, are you looking at that timeline?



##########
airflow-core/src/airflow/dag_processing/manager.py:
##########
@@ -1141,14 +1142,42 @@ def process_parse_results(
         stat.import_errors = 1
     else:
         # record DAGs and import errors to database
-        update_dag_parsing_results_in_db(
-            bundle_name=bundle_name,
-            bundle_version=bundle_version,
-            dags=parsing_result.serialized_dags,
-            import_errors=parsing_result.import_errors or {},
-            warnings=set(parsing_result.warnings or []),
-            session=session,
-        )
+        logging.info(f"Updating DAGs and import errors to database for bundle 
{bundle_name} "
+                     f"and version {bundle_version}")
+
+        # check a flag to see whether to call api or directly update db
+        if conf.getboolean("dag_processor", "use_api_for_updating_dags", 
fallback=False):
+            server_url = conf.get("core", "execution_api_server_url")
+            if not server_url:
+                raise AirflowConfigException("execution_api_server_url is not 
set")
+
+            logging.info("Attempting to make an API call to update DAGs using 
the execution API server.")
+
+            @tenacity.retry(
+                stop=tenacity.stop_after_attempt(5),
+                wait=tenacity.wait_exponential(multiplier=1, min=4, max=15),
+                before_sleep=lambda retry_state: logging.info(
+                    "Retrying update_dag_parsing_results_in_db. Attempt %d", 
retry_state.attempt_number
+                ),
+            )
+            def _update_dags_via_api():
+                client = Client(base_url=server_url, token="")
+                client.post(
+                    
f"/dags/update_dags?bundle_name={bundle_name}&bundle_version={bundle_version}",
+                    data=parsing_result.model_dump_json(),
+                    headers={"Content-Type": "application/json"},
+                )
+            _update_dags_via_api()

Review Comment:
   Are the ad hoc dag processors running in a different network space?



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