python - Is there way to call task within the task in Airflow?
问题描述
I have the following logic:
def function_1():
if condition_1 == True:
function_2()
else:
function_3()
function_2()
Is there any way to call the task within the task in Airflow?
解决方案
You can achieve the same using BranchPythonOperator as below.
def function_1(**kwargs):
if condition_1 == True :
return 'function_2'
else:
return 'function_3'
check_task = BranchPythonOperator(
task_id='check_task',
python_callable=function_1, # defined above method holds the branching condition
provide_context=True,
dag=dag
)
function_2_task = BashOperator(
task_id= 'function_2',
bash_command="echo function_2 task executed",
dag=dag
)
function_3_task = BashOperator(
task_id= 'function_3',
bash_command="echo function_3 task executed",
dag=dag
)
function_2_task.set_upstream(check_task)
function_3_task.set_upstream(check_task)
function_3_task.set_upstream(function_2_task)
推荐阅读
- sas - 如何计算SAS中非零序列的长度
- python - 沿张量流中 (batch, 13, 13, 3, 1) 张量的最后一个维度的前 k 个
- c# - 将对象平滑移动到目标 Unity3D
- asp.net - MSbuild 网站未发布到本地目录
- javascript - 当用户使用 jQuery 滚动时,在不同的 div 中触发滚动事件
- dynamic - Hyperledger 私有数据动态访问
- arrays - 结果不一致 - Jupyter Numpy & Transpose
- javascript - Javascript Promise 保证 - Javascript 事件循环
- google-cloud-platform - 谷歌云控制台虚拟机被神秘删除
- javascript - 如何让引导卡留在reactjs中的屏幕中间