Airflow 是一个用于创建、调度和监控工作流的平台
apache-airflow
。如果您还没有安装,请使用以下命令安装:pip install apache-airflow
# dags/example_dag.py
from datetime import datetime, timedelta
from airflow import DAG
from airflow.operators.dummy_operator import DummyOperator
default_args = {
'owner': 'airflow',
'depends_on_past': False,
'start_date': datetime(2021, 1, 1),
'email_on_failure': False,
'email_on_retry': False,
'retries': 1,
'retry_delay': timedelta(minutes=5),
}
dag = DAG(
'example_dag',
default_args=default_args,
description='A simple example DAG',
schedule_interval=timedelta(days=1),
)
start = DummyOperator(task_id='start', dag=dag)
end = DummyOperator(task_id='end', dag=dag)
start >> end
# tests/test_example_dag.py
import unittest
from airflow.models import DagBag
class TestExampleDag(unittest.TestCase):
def setUp(self):
self.dagbag = DagBag()
def test_example_dag(self):
dag = self.dagbag.get_dag(dag_id='example_dag')
self.assertIsNotNone(dag)
self.assertEqual(len(dag.tasks), 2)
self.assertIn('start', dag.task_ids)
self.assertIn('end', dag.task_ids)
if __name__ == '__main__':
unittest.main()
python -m unittest tests/test_example_dag.py
领取专属 10元无门槛券
手把手带您无忧上云