Python Operator 란?
▪ python 함수를 실행해주는 operator로 가장 많이 쓰임
dags_python_operator.py
▪ 매일 6시 30분에 작업하도록 스케줄링
▪ 리스트에 포함된 과일을 랜덤하게 print 해주는 select_fruit() 함수 작성
▪ PythonOperator의 "python_callable"에 실행하고자 하는 함수를 넣어주면 됨
from airflow import DAG
import pendulum
import datetime
from airflow.operators.python import PythonOperator
import random
with DAG(
dag_id="dags_python_operator",
schedule="30 6 * * *",
start_date=pendulum.datetime(2023, 3, 1, tz="Asia/Seoul"),
catchup=False
) as dag:
def select_fruit():
fruit = ['APPLE','BANANA','ORANGE','AVOCADO']
rand_int = random.randint(0,3)
print(fruit[rand_int])
py_t1 = PythonOperator(
task_id='py_t1',
python_callable=select_fruit
)
py_t1
Dag 실행하기
▪ dag 업로드 후 webserver 접속
▪ dag을 unpause 시키고 log를 확인해보면 작성한 함수가 정상적으로 실행되었음
참고:
Airflow 마스터 클래스 강의 - 인프런
데이터 파이프라인을 효율적으로 만들고 관리하기 위한 Orchestration 도구인 Airflow에 대해 배우는 강의입니다. 초보자도 차근차근 배울 수 있는 Airflow 마스터 클래스, 환영합니다!, 데이터 파이프
www.inflearn.com
'Data Engineering > Airflow' 카테고리의 다른 글
[Airflow] Task decorator 사용하기 (0) | 2024.01.21 |
---|---|
[Airflow] 외부 python 함수 실행하기 (0) | 2024.01.21 |
[Airflow] Email Operator 사용하기 (0) | 2024.01.21 |
[Airflow] Bash Operator & 외부 Shell 파일 실행하기 (0) | 2024.01.20 |
[Airflow] Task 연결하기 (1) | 2024.01.16 |