You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/06/23 13:47:04 UTC

[GitHub] [airflow] ephraimbuddy commented on a change in pull request #9330: Add read-only Task endpoint

ephraimbuddy commented on a change in pull request #9330:
URL: https://github.com/apache/airflow/pull/9330#discussion_r444236641



##########
File path: airflow/api_connexion/endpoints/task_endpoint.py
##########
@@ -14,20 +14,36 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+from flask import current_app
 
-# TODO(mik-laj): We have to implement it.
-#     Do you want to help? Please look at: https://github.com/apache/airflow/issues/8138
+from airflow import DAG
+from airflow.api_connexion.exceptions import NotFound
+from airflow.api_connexion.schemas.task_schema import TaskCollection, task_collection_schema, task_schema
+from airflow.exceptions import TaskNotFound
 
 
-def get_task():
+def get_task(dag_id, task_id):
     """
     Get simplified representation of a task.
     """
-    raise NotImplementedError("Not implemented yet.")
+    dag: DAG = current_app.dag_bag.get_dag(dag_id)
+    if not dag:
+        raise NotFound("DAG not found")
 
+    try:
+        task = dag.get_task(task_id=task_id)
+    except TaskNotFound:
+        raise NotFound("Task not found")
+    return task_schema.dump(task)
 
-def get_tasks():
+
+def get_tasks(dag_id):
     """
     Get tasks for DAG
     """
-    raise NotImplementedError("Not implemented yet.")
+    dag: DAG = current_app.dag_bag.get_dag(dag_id)
+    if not dag:
+        raise NotFound("DAG not found")
+    tasks = dag.tasks
+    task_collection = TaskCollection(tasks=tasks, total_entries=len(tasks))

Review comment:
       The` total_entries` is not actually the total of query result. In this case now, It is the total of all tasks in the db.




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