【问题标题】:Trigger DAG Run on environment startup/restart在环境启动/重启时触发 DAG 运行
【发布时间】:2023-01-17 21:51:39
【问题描述】:

有没有办法在每次启动气流环境时触发 DAG?这将有助于对环境进行一些测试

【问题讨论】:

    标签: airflow airflow-scheduler


    【解决方案1】:

    您可以监控系统或进程的启动时间,并查看 Dag 的最后执行日期时间,并据此触发 dag。

    你可以参考下面的代码

    
    import psutil
    from datetime import datetime
    last_reboot = psutil.boot_time()
    boot_time = datetime.fromtimestamp(last_reboot)
    
    Variable.set('boot_time',boot_time.strftime("%Y-%m-%d %H:%M:%S"))
    last_run_dt = Variable.get('last_run_end_date',"")
    try:
        from dateutil import parser
    
        if last_run_dt == "":
            last_run_at = parser.parse('1970-01-01 00:00:00')
        else:
            last_run_at = parser.parse(last_run_dt)
    
        if boot_time > last_run_at:
            # Your code to trigger the Dag               
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-16
      • 2014-10-09
      • 2022-11-04
      • 1970-01-01
      • 2014-12-06
      • 1970-01-01
      • 2011-12-04
      • 1970-01-01
      相关资源
      最近更新 更多