DAG 외부 함수 호출 , 파이썬 모듈 경로 이해
from airflow.operators.python import PythonOperator
파이썬은 위 경로를 어떻게 찾을까 ?
: dag에서 외부 함수를 import할때 경로는 어떻게 해야하는지 이해하기 위함
sys.path 변수에서 모듈 경로 검색



from airflow import DAG
import datetime
import pendulum
from airflow.operators.python import PythonOperator
from common.common_func import get_sftp
with DAG(
dag_id="dags_python_import_operator",
schedule="30 6 * * *", # 분/시/일/월/요일
start_date=pendulum.datetime(2023, 3, 1, tz="Asia/Seoul"),
catchup=False
) as dag:
task_get_sftp = PythonOperator(
task_id ="task_get_sftp",
python_callable=get_sftp
)
def get_sftp():
print('sftp 작업을 시작합니다')
참고
local에서
from common.common_func import get_sftp
이 부분 에러 발생, local syspath에는 plugins가 등록되어 있지 않기 때문.
상위 airflow 폴더 바로 아래 .env 만들어서 syspath등록 필요
(git에 올릴필요는 없기 때문에 .gitignore에 추가 )
