简体   繁体   English

Airflow ExternalTaskSensor 手动触发

[英]Airflow ExternalTaskSensor manually triggered

I have created two dags which I want to trigger manually schedule_interval=None .我创建了两个要手动触发的 dags schedule_interval=None

First, I trigger "External_test_A" which should be pending till the "External_test_B" will not be triggered.首先,我触发了“External_test_A”,它应该一直挂起,直到“External_test_B”不会被触发。 After a while (after 2 minutes) I trigger "External_test_B" DAG, which runs only one task first_task .过了一会儿(2 分钟后),我触发了“External_test_B”DAG,它只运行一个任务first_task

When the task: first_task is success, then Poking for External_test_B.first_task from "External_test_A", should finished, return success and run second_task task from "External_test_A".当任务: first_task成功时,从“External_test_A”中探查Poking for External_test_B.first_task应该完成,返回成功并从“External_test_A”运行second_task任务。

I stuck in the situation where even if first_task is a success, the Poking for... from "External_test_A" is still going.我陷入了即使first_task成功,“External_test_A”中的Poking for...仍在继续的情况。

External_test_A:外部测试A:

default_args = {
    'owner': 'airflow',
    'start_date': pendulum.yesterday().astimezone('US/Eastern')
}

dag = DAG(
    dag_id='External_test_A',
    default_args=default_args,
    schedule_interval=None
)

def do_second_task():
    print('Second task is done')

sensor = ExternalTaskSensor(
    task_id='wait_for_the_first_task_to_be_completed',
    external_dag_id='External_test_B',
    external_task_id='first_task',
    execution_delta=timedelta(minutes=3),
    dag=dag)

t2 = PythonOperator(
    task_id='second_task',
    python_callable=do_second_task,
    dag=dag)

sensor >> t2

if __name__ == "__main__":
    dag.cli()

External_test_B:外部测试B:

default_args = {
    'owner': 'airflow',
    'start_date': pendulum.yesterday().astimezone('US/Eastern')
}

dag = DAG(
    dag_id='External_test_B',
    default_args=default_args,
    schedule_interval=None
)

t1 = DummyOperator(task_id='first_task', dag=dag)

t1

if __name__ == "__main__":
    dag.cli()

Does some of you could tell me what I'm doing wrong?你们中的一些人能告诉我我做错了什么吗? How to solve the problem with communication between two tasks from two different DAGs using only manual trigger?如何仅使用手动触发来解决来自两个不同 DAG 的两个任务之间的通信问题?

After a lot of research there is no way to do this with manual trigger unless you write your own class to do the job.经过大量研究,除非您编写自己的 class 来完成这项工作,否则无法使用手动触发来执行此操作。 Both dags have to have a schedule interval with same start date and you need to mention execution_delta in external sensor definition.两个 dag 都必须有一个具有相同开始日期的计划间隔,并且您需要在外部传感器定义中提及 execution_delta。

There is no solution to your problem since both of your dags are manually triggered.由于您的两个 dag 都是手动触发的,因此无法解决您的问题。 I suggest you try to do it in one DAG...我建议您尝试在一个 DAG 中执行此操作...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM