如何获得手动触发 DAG 的 Airflow 用户? [英] How to get Airflow user who manually trigger a DAG?

查看:29
本文介绍了如何获得手动触发 DAG 的 Airflow 用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Airflow UI 中,浏览器 > 日志"下可用的日志事件之一是事件触发器"以及负责触发此事件的 DAG ID 和所有者/用户.是否可以通过编程轻松获取此信息?

In the Airflow UI, one of the log events available under "Browser > Logs" is the event "Trigger" along with the DAG ID and Owner/User who's responsible for triggering this event. Is this information easily obtainable programmatically?

用例是,我有一个 DAG,它允许一部分用户手动触发执行.根据触发此 DAG 执行的用户,此 DAG 执行代码的行为会有所不同.

The use case is, I have a DAG that allows a subset of users to manually trigger the execution. Depending on the user who triggers the execution of this DAG, the behavior of code execution from this DAG will be different.

提前致谢.

推荐答案

可以直接从Airflow Metadata Database的Log表中获取,如下:

You can directly fetch it from the Log table in the Airflow Metadata Database as follows:

from airflow.models.log import Log
from airflow.utils.db import create_session

with create_session() as session:
   results = session.query(Log.dttm, Log.dag_id, Log.execution_date, Log.owner, Log.extra).filter(Log.dag_id == 'example_trigger_target_dag', Log.event == 'trigger').all()

# Get top 2 records
results[2]

输出:

(datetime.datetime(2020, 3, 30, 23, 16, 52, 487095, tzinfo=<TimezoneInfo [UTC, GMT, +00:00:00, STD]>),
 'example_trigger_target_dag',
 None,
 'admin',
 '[(\'dag_id\', \'example_trigger_target_dag\'), (\'origin\', \'/tree?dag_id=example_trigger_target_dag\'), (\'csrf_token\', \'IjhmYzQ4MGU2NGFjMzg2ZWI3ZjgyMTA1MWM3N2RhYmZiOThkOTFhMTYi.XoJ92A.5q35ClFnQjKRiWwata8dNlVs-98\'), (\'conf\', \'{"message": "kaxil"}\')]')

这篇关于如何获得手动触发 DAG 的 Airflow 用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆