Airflow 센서

Python으로 배우는 Apache Airflow 입문

Mike Metzger

Data Engineer

센서

  • 특정 조건이 충족될 때까지 대기하는 오퍼레이터
    • 파일 생성
    • 데이터베이스 레코드 업로드
    • 웹 요청 응답
  • 조건 확인 주기 설정 가능
  • 태스크에 할당

조건이 충족될 때까지 대기하는 Airflow 센서 설명

Python으로 배우는 Apache Airflow 입문

센서 세부 정보

  • airflow.sdk.BaseSensorOperator에서 파생
  • 센서 인수:
  • mode - 조건 확인 방식
    • mode='poke' - 기본값, 반복 실행
    • mode='reschedule' - 태스크 슬롯 반환 후 재시도
  • poke_interval - 확인 간격
  • timeout - 태스크 실패 전 대기 시간
  • 일반 오퍼레이터 속성도 포함
Python으로 배우는 Apache Airflow 입문

파일 센서

  • airflow.providers.standard.sensors 라이브러리에 포함
  • 특정 경로의 파일 존재 여부 확인
  • 디렉터리 내 파일 존재 여부도 확인 가능
from airflow.providers.standard.sensors.filesystem import FileSensor

file_sensor_task = FileSensor(task_id='file_sense',
                              filepath='salesdata.csv',
                              poke_interval=300,
                              timeout=3000
                              )

init_sales_cleanup() >> file_sensor_task >> generate_report()
Python으로 배우는 Apache Airflow 입문

기타 센서

  • airflow.providers.*.sensors에 다양한 센서 존재
  • ExternalTaskSensor - 다른 DAG의 태스크 완료 대기
  • HttpSensor - 웹 URL 요청 후 콘텐츠 확인
  • SqlSensor - SQL 쿼리 실행 후 콘텐츠 확인
Python으로 배우는 Apache Airflow 입문

센서는 언제 사용하나요?

  • 조건 충족 시점이 불확실한 경우
  • 즉각적인 실패가 바람직하지 않은 경우
  • 루프 없이 태스크 반복 추가

 

 

조건이 충족될 때까지 대기하는 Airflow 센서 설명

Python으로 배우는 Apache Airflow 입문

연습해 봅시다!

Python으로 배우는 Apache Airflow 입문

Preparing Video For Download...