我正在使用 Windows 机器并创建了气流容器。我可以通过 DAG 读取本地文件系统上的数据,但无法将数据写入文件。我也尝试过给出完整路径,也尝试过不同的运算符:Python 和 Bash,但它仍然不起作用。DAG 成功,没有任何失败可显示。注意: /opt/airflow : 是 $AIRFLOW_HOME 路径
可能是什么原因?
一段代码:
from airflow import DAG
from datetime import datetime
from airflow.operators.python import PythonOperator
from airflow.operators.bash import BashOperator
def pre_process():
f = open("/opt/airflow/write.txt", "w")
f.write("world")
f.close()
with DAG(dag_id="test_data", start_date=datetime(2021, 11, 24), schedule_interval='@daily') as dag:
check_file = BashOperator(
task_id="check_file",
bash_command="echo Hi > /opt/airflow/hi.txt "
)
pre_processing = PythonOperator(
task_id="pre_process",
python_callable=pre_process
)
check_file >> pre_processing