데이터 엔지니어링/AirFlow

[Airflow] 기반의 데이터 파이프라인(5) - 백필(BackFilling)

안용감한호랑이 2023. 10. 14. 00:00

Workflow를 개발, 운영해본 입장이라면 과거데이터 재소급 등의 이유로 과거 시점의 데이터 처리를 진행할 필요가 있다는 것을 알고 있을 것이다.

Airflow의 BackFilling은 이를 위해 존재한다.

 

출처 : Apache Airflow 기반의 데이터 파이프라인

dag=DAG(
	dag_id="backfill_examples",
    schedule_interval="@daily",         # 매일 자정에 실행되도록 DAG를 스케줄하는 매크로
    start_date=dt.datetime(2023.1.1),   # 2023.1.1 부터 DAG 실행 스케줄을 시작할 날짜/시간
    end_date=dt.datetime(2023.12.31),   # 2023.12.31 까지 DAG가 실행된다.
    catchup=True,
    # ...생략...
)

catchup=True 인 경우 현재 시점보다 과거 시점의 작업 또한 수행하게 된다.

( 글 작성 시점인 2023-10-12 이전인 2023-01-01 ~ 2023-10-11 까지 수행)

 

 

 

 

BackFill 수행

backfill Document 에서 backfill은 CLI로 수행하도록 되어있다.

 

DAG Runs — Airflow Documentation

 

airflow.apache.org

주의사항 : backfill 수행 시 과거 시점의 job이 동시 수행되어 서버에 많은 부하를 일으킬 수 있다.

 

BackFill 옵션

backfill Command Document

 

Command Line Interface and Environment Variables Reference — Airflow Documentation

 

airflow.apache.org

airflow dags backfill [-h] [-c CONF] [--continue-on-failures]
                      [--delay-on-limit DELAY_ON_LIMIT] [-x] [-n]
                      [-e END_DATE] [-i] [-I] [-l] [-m] [--pool POOL]
                      [--rerun-failed-tasks] [--reset-dagruns] [-B]
                      [-s START_DATE] [-S SUBDIR] [-t TASK_REGEX] [-v] [-y]
                      dag_id
  • -c, --conf
    • DagRun의 conf attribute를 JSON으로 전달할 때 사용한다.
  • --continue-on-failures 
    • Defulat : False
    • BackFill 수행중 task들이 실패해도 BackFill은 실패하지 않게된다.
  • --delay-on-limit
    • max_active_runs 옵션에 의해 dag 실행이 제한되면 대기하는 시간(초)
  • -e, --end-date
    • end_date 정의
  • -s, --start-date
    • start_date 정의
  • -v, --verbose
    • 로깅 출력을 더 자세하게 출력

 

더 많은 옵션들의 설명은 공식문서를 참고부탁 드립니다.