我试图触发竹子的气流并试图使其在前台运行,以便竹子可以知道触发器何时完成执行。
有人可以建议我如何让Bamboo等待远程服务器上的气流触发执行? 如果气流dag执行成功,是否有可能捕获结果,从而使竹子可以标记构建失败或成功?
答案 0 :(得分:0)
触发气流dag之后,捕获执行日期并每隔几秒钟检查一次dag_status,然后返回状态为“成功”还是“失败”。
这是我写的脚本:
try_log.py
import re
import os
import sys
import time
f = open('log.txt', 'r')
outs = f.readlines()
regex = r"Created.*?@(.*?)\s(.*?)manual"
matches = re.findall(regex, str(outs), re.MULTILINE)
dag_exec_date = matches[0][1].strip()[0:-1]
status = 'running'
while status not in ['failed', 'success']:
stream = os.popen("airflow dag_state dag_id '{}'".format(dag_exec_date))
output = stream.read()
lines = output.split('\n')
status = lines[-2].strip()
if status not in ['failed', 'success']:
time.sleep(60)
else:
print (status)
exit()
Bamboo SSH任务中添加了以下内容,以执行气流触发并等待状态完成
airflow trigger_dag ${bamboo.dag_id} > /path/log.txt
outputs=$(python try_log.py)
if [ "$outputs" = "failed" ]; then
echo "status failed. Exiting and failing build"
exit 125
fi