dazza-codes commented on a change in pull request #7027: [WIP][AIRFLOW-6441] 
KnativeExecutor
URL: https://github.com/apache/airflow/pull/7027#discussion_r367507948
 
 

 ##########
 File path: airflow/executors/knative_executor.py
 ##########
 @@ -0,0 +1,210 @@
+# -*- 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.
+"""
+This module contains KnativeExecutor which is optimized
+for running lots of short tasks in a scalable, efficient manner.
+"""
+
+import asyncio
+import datetime
+import functools
+import multiprocessing
+
+import aiohttp
+from cached_property import cached_property
+
+from airflow.configuration import conf
+from airflow.exceptions import AirflowConfigException, AirflowException
+from airflow.executors.base_executor import BaseExecutor
+from airflow.executors.kubernetes_executor import KubernetesExecutor
+from airflow.utils.log.logging_mixin import LoggingMixin
+from airflow.utils.state import State
+
+
+async def make_request_async(
+    task_id,
+    dag_id,
+    execution_date,
+    host,
+    log,
+    host_header=None,
+) -> aiohttp.ClientResponse:
+    """
+
+    Thius function crafts a request to an external airflow server. This server 
is assumed to be
+    a knative service.
+    @param task_id:
+    @param dag_id:
+    @param execution_date:
+    @param host:
+    @param log:
+    @param host_header:
+    @return:
+    """
+    req = "http://"; + host + "/run"
+
+    date = int(datetime.datetime.timestamp(execution_date))
+    params = {
+        "task_id": task_id,
+        "dag_id": dag_id,
+        "execution_date": date,
+    }
+    headers = {}
+    if host_header:
+        headers["Host"] = host_header
+    timeout = aiohttp.ClientTimeout(total=60000)
+    async with aiohttp.ClientSession(timeout=timeout) as session:
+        async with session.get(url=req, params=params, headers=headers) as 
resp:
+            log.info(resp.status)
+            log.info(await resp.text())
+            return resp
+
+
+class KnativeRequestLoop(multiprocessing.Process, LoggingMixin):
+    """
+
+    This class asynchronously pulls tasks from the KnativeExecutor and runs 
them as coroutines using asyncio
+
+    """
 
 Review comment:
   +1 - also consider this pattern at
   - 
https://gist.github.com/seglberg/0b4487b57b4fd425c56ad72aba9971be#file-grpc_asyncio-py-L21

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to