Airflow可以通过PythonOperator运行Python函数。以下是代码示例:
from airflow import DAG
from airflow.operators.python_operator import PythonOperator
from datetime import datetime
dag = DAG('my_dag', description='My first DAG',
schedule_interval='0 12 * * *',
start_date=datetime(2018, 11, 1), catchup=False)
def my_function():
print('Hello, World!')
run_this = PythonOperator(task_id='run_this', python_callable=my_function, dag=dag)
在上面的例子中,我们定义了一个名为“my_function”的Python函数,并通过PythonOperator将该函数添加到DAG的任务列表中。此后,run_this任务将会运行该函数。当我们运行DAG时,Airflow会创建一个新的Python进程来执行my_function。在Airflow的Web UI中,你可以查看任务的日志,以便了解函数的执行情况。