第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在另一個達格氣流中創(chuàng)建達格斯

如何在另一個達格氣流中創(chuàng)建達格斯

牧羊人nacy 2022-09-13 15:10:19
我正在嘗試擁有一個主匕首,它將根據(jù)我的需要創(chuàng)建更多的匕首。我在氣流.cfg dags_folder中有以下python文件。此代碼在數(shù)據(jù)庫中創(chuàng)建主 dag。此主 dag 應(yīng)讀取文本文件,并應(yīng)為文本文件中的每一行創(chuàng)建 dag。但是,在主 dag 中創(chuàng)建的 dag 不會添加到數(shù)據(jù)庫中。創(chuàng)建它的正確方法是什么?版本詳細信息:蟒蛇版本:3.7阿帕奇氣流版本:1.10.8import datetime as dtfrom airflow import DAGfrom airflow.operators.bash_operator import BashOperatorfrom airflow.operators.python_operator import PythonOperatorroot_dir = "/home/user/TestSpace/airflow_check/res"print("\n\n ===> \n Dag generator")default_args = {    'owner': 'airflow',    'start_date': dt.datetime(2020, 3, 22, 00, 00, 00),    'concurrency': 1,    'retries': 0}def greet(_name):    message = "Greetings {} at UTC: {} Local: {}\n".format(_name, dt.datetime.utcnow(), dt.datetime.now())    f = open("{}/greetings.txt".format(root_dir), "a+")    print("\n\n =====> {}\n\n".format(message))    f.write(message)    f.close()def create_dag(dag_name):    with DAG(dag_name, default_args=default_args,             schedule_interval='*/2 * * * *',             catchup=False             ) as i_dag:        i_opr_greet = PythonOperator(task_id='greet', python_callable=greet,                                     op_args=["{}_{}".format("greet", dag_name)])        i_echo_op = BashOperator(task_id='echo', bash_command='echo `date`')        i_opr_greet >> i_echo_op    return i_dagdef create_all_dags():    all_lines = []    f = open("{}/../dag_names.txt".format(root_dir), "r")    for x in f:        all_lines.append(str(x))    f.close()    for line in all_lines:        print("Dag creation for {}".format(line))        globals()[line] = create_dag(line)with DAG('master_dag', default_args=default_args,         schedule_interval='*/1 * * * *',         catchup=False         ) as dag:    echo_op = BashOperator(task_id='echo', bash_command='echo `date`')    create_op = PythonOperator(task_id='create_dag', python_callable=create_all_dags)    echo_op >> create_op
查看完整描述

2 回答

?
慕少森

TA貢獻2019條經(jīng)驗 獲得超9個贊

您有 2 個選項:

  1. 使用子操作程序示例 DAG。如果您的計劃間隔可以相同,請使用它。

  2. 編寫蟒蛇 DAG 文件:從主 DAG 開始,在包含 DAG 的AIRFLOW_HOME中創(chuàng)建 Python 文件。為此,您可以使用 Jinja2 模板引擎。


查看完整回答
反對 回復(fù) 2022-09-13
  • 2 回答
  • 0 關(guān)注
  • 103 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號