def get_task(dag_id, task_id):
    """Get simplified representation of a task."""
    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)
Example #2
0
 def test_serialize(self):
     op = DummyOperator(
         task_id="task_id",
         start_date=datetime(2020, 6, 16),
         end_date=datetime(2020, 6, 26),
     )
     result = task_schema.dump(op)
     expected = {
         "class_ref": {
             "module_path": "airflow.operators.dummy",
             "class_name": "DummyOperator",
         },
         "depends_on_past": False,
         "downstream_task_ids": [],
         "end_date": "2020-06-26T00:00:00+00:00",
         "execution_timeout": None,
         "extra_links": [],
         "owner": "airflow",
         "pool": "default_pool",
         "pool_slots": 1.0,
         "priority_weight": 1.0,
         "queue": "default",
         "retries": 0.0,
         "retry_delay": {
             "__type": "TimeDelta",
             "days": 0,
             "seconds": 300,
             "microseconds": 0
         },
         "retry_exponential_backoff": False,
         "start_date": "2020-06-16T00:00:00+00:00",
         "task_id": "task_id",
         "template_fields": [],
         "trigger_rule": "all_success",
         "ui_color": "#e8f7e4",
         "ui_fgcolor": "#000",
         "wait_for_downstream": False,
         "weight_rule": "downstream",
     }
     assert expected == result