Reputation: 1451
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.
Upvotes: 1
Views: 1655
Reputation: 11597
The question is not clear, but from whatever I can infer, I'll try to clear your doubts
not all the operators that I use has xcom support
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
operator
s)
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.
It is straightforward (and no-brainer) to separate-out Variable
s on per-DAG
basis (see point (6)); but yes for different DagRun
s 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 Xcom
s.
Additionally, if you want to manipulate Variable
s (or any other Airflow
model) at runtime (though I would recommend you to avoid it particularly for Variable
s), Airflow
also gives completely liberty to exploit the underlying SQLAlchemy ORM
framework for that. You can take inspiration from this.
Upvotes: 1