本文介绍了如何设置一个变量仅在特定的dag_run期间使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 如何设置用于特定dag_run的变量。我知道可以在xcom中设置值,但并不是我使用的所有运算符都具有xcom支持。我也不想将值存储到Variables数据存储中,以防在当前运行时开始另一次dag运行而需要存储其他值。How do I set a variable for use during a particular dag_run. I'm aware of setting values in xcom, but not all the operators that I use has xcom support. I also would not like to store the value into the Variables datastore, in case another dag run begins while the current one is running, that need to store different values.推荐答案问题尚不清楚,但是根据我的推断,我将尽力消除您的疑虑The question is not clear, but from whatever I can infer, I'll try to clear your doubts显然您已经将 xcom 与其他构造误认为是因为 xcom 功能是 TaskInstance 的一部分以及功能 xcom_push() 和 xcom_pull() 是在 BaseOperator 本身(是所有 Airflow 操作符 s)Apparently you've mistaken xcom with some other construct because xcom feature is part of TaskInstance and the functions xcom_push() and xcom_pull() are defined in BaseOperator itself (which is the parent of all Airflow operators)很容易(而且很容易)将分离出的变量 - DAG 基础(请参阅点(6));但是可以,对于单个 DAG 的不同 DagRun ,这种隔离将是一个挑战。我可以认为 xcom 是最简单的解决方法。请查看此,以了解 Xcom s的用法。 。It is straightforward (and no-brainer) to separate-out Variables on per-DAG basis (see point (6)); but yes for different DagRuns of a single DAG, this kind of isolation would be a challenge. I can think of xcom to be the easiest workaround for this. Have a look at this for some insights on usage of Xcoms.此外,如果要操作变量 s (或任何其他 Airflow 模型)在运行时 (尽管我建议您避免尤其是对于 Variable s), Airflow 也提供了完全自由地利用底层的 SQLAlchemy ORM 框架。您可以从此中获得启发。Additionally, if you want to manipulate Variables (or any other Airflow model) at runtime (though I would recommend you to avoid it particularly for Variables), Airflow also gives completely liberty to exploit the underlying SQLAlchemy ORM framework for that. You can take inspiration from this. 这篇关于如何设置一个变量仅在特定的dag_run期间使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-13 07:49