airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [airflow] dimberman commented on a change in pull request #7027: [WIP][AIRFLOW-6441] KnativeExecutor
Date Tue, 07 Jan 2020 17:25:34 GMT
dimberman commented on a change in pull request #7027: [WIP][AIRFLOW-6441] KnativeExecutor
URL: https://github.com/apache/airflow/pull/7027#discussion_r363860537
 
 

 ##########
 File path: airflow/knative_worker/knative_task_runner.py
 ##########
 @@ -0,0 +1,132 @@
+# -*- coding: utf-8 -*-
+#
+# 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.
+#
+
+# pylint: disable=missing-docstring
+
+
+import logging
+import os
+from datetime import datetime
+from typing import Any
+
+import pendulum
+from flask import request
+from flask_api import FlaskAPI
+
+from airflow import settings
+from airflow.exceptions import AirflowException
+from airflow.jobs import LocalTaskJob
+from airflow.models import DAG, DagBag, TaskInstance
+from airflow.utils.log.logging_mixin import LoggingMixin
+
+app = None  # type: Any
+DAGS_FOLDER = settings.DAGS_FOLDER
+app = FlaskAPI(__name__)
+
+
+@app.route("/health")
+def health():
+    """
+    Basic health function for testing
+
+    @return:
+    """
+    name = request.args.get("name")
+    return "Hello, {}..".format(name)
+
+
+@app.route("/run")
+def run_task():
+    """
+    Runs a single airflow task from beginning to end.
+    Returns 200 even if task fails because results were posted to database
+    Returns 500 in case of system failure
+    @return:
+    """
+    dag_id = request.args.get('dag_id')
+    task_id = request.args.get('task_id')
+    # subdir = request.rel_url.query['subdir']
+    # subdir = "/root/airflow/dags"
+    subdir = None
+    execution_date = pendulum.fromtimestamp(int(request.args.get("execution_date")))
+    log = LoggingMixin().log
+    log.info("running dag {} for task {} on date {} in subdir {}"
+             .format(dag_id, task_id, execution_date, subdir))
+    logging.shutdown()
+    try:
+        # IMPORTANT, have to use the NullPool, otherwise, each "run" command may leave
+        # behind multiple open sleeping connections while heartbeating, which could
+        # easily exceed the database connection limit when
+        # processing hundreds of simultaneous tasks.
+        settings.configure_orm(disable_connection_pool=True)
+
+        ti = _get_task_instance(dag_id=dag_id,
+                                task_id=task_id,
+                                subdir=subdir,
+                                execution_date=execution_date)
+        local_job = LocalTaskJob(
+            task_instance=ti,
+        )
+        local_job.run()
 
 Review comment:
   Hugely agree. The cyclical nature of going back through the CLI makes testing/comprehending
the code much harder.

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

Mime
View raw message