[Airflow] Task 재실행하기

반응형

Airflow 이용하다 보면 특정 task를 다시 실행하고 싶은 경우들이 있다. 

Task를 재실행하는 법에 대해서 알아보자.

 

 

Airflow UI 이용

Airflow UI에 접속해서 재실행할 DAG를 클릭하자.

 

Graph View를 클릭하자.

재실행할 Task 클릭하자.

 

Task를 클릭하면 아래와 같은 창이 뜬다. 원하는 옵션을 선택하고 Clear를 클릭하자.

 

Clear를 클릭하면 재실행할 Task를 확인할 수 있다.

맞으면 OK를 클릭해서 Task를 재실행하자.

 

 


 

Airflow CLI 이용

command line 이용해서도 동일하게 할 수 있다.

airflow tasks clear command를 이용하면 된다.

옵션을 잘 모르겠으면 help 명령어로 사용법을 확인해보자.

 airflow tasks clear -h 

 

 

위에서 버튼으로 클릭한 옵션들은 아래와 같이 입력할 수 있다.

-f, --only-failed     Only failed jobs
-r, --only-running    Only running jobs
-d, --downstream      Include downstream tasks
-u, --upstream        Include upstream tasks
-X, --exclude-parentdag
                Exclude ParentDAGS if the task cleared is a part of a SubDAG
-x, --exclude-subdags
                Exclude subdags

 

 

위 Airflow UI 이용한 방법에서 실행한 옵션대로 하면 아래와 같이 입력하면 된다.

airflow tasks clear ${dag_id} \
    --task-regex ${task_regex} \
    --start-date ${START_DATE} \ 
        -d

실행하면 역시 재실행할 task를 확인한다.

You are about to delete these 6 tasks:
<TaskInstance: example_python_operator.print_the_context 2021-08-05 15:16:08.226059+00:00 [success]>
<TaskInstance: example_python_operator.sleep_for_0 2021-08-05 15:16:08.226059+00:00 [success]>
<TaskInstance: example_python_operator.sleep_for_1 2021-08-05 15:16:08.226059+00:00 [success]>
<TaskInstance: example_python_operator.sleep_for_2 2021-08-05 15:16:08.226059+00:00 [success]>
<TaskInstance: example_python_operator.sleep_for_3 2021-08-05 15:16:08.226059+00:00 [success]>
<TaskInstance: example_python_operator.sleep_for_4 2021-08-05 15:16:08.226059+00:00 [success]>

Are you sure? (yes/no):

확인하고 맞으면 yes를 입력하면 된다.

그러면 task가 재실행된다.

 

 

 

 

참고