【发布时间】:2023-01-17 21:51:39
【问题描述】:
有没有办法在每次启动气流环境时触发 DAG?这将有助于对环境进行一些测试
【问题讨论】:
有没有办法在每次启动气流环境时触发 DAG?这将有助于对环境进行一些测试
【问题讨论】:
您可以监控系统或进程的启动时间,并查看 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
【讨论】: