DAG 4

Airflow query csv export, 쿼리로 csv export

공식문서를 기반으로 만들었다. https://airflow.apache.org/docs/apache-airflow/stable/_api/airflow/hooks/dbapi/index.html#airflow.hooks.dbapi.DbApiHook.get_pandas_df 아래 내용을 토대로 만들었다. https://pepega.tistory.com/49 전체 코드는 아래에 있다. https://github.com/GHGHGHKO/airflow/commit/7509b3c13816629c450afc8f8a325143c1da1d65 기존에는 get_records 메서드를 활용했다. def execute(self, context): hook = PostgresHook( postgres_conn_id = self...

Airflow 2022.03.20

Airflow XComs Email 전송

Airflow로 Email 전송하는 글을 포스팅했었다. https://pepega.tistory.com/47 블로그 코드는 https://github.com/GHGHGHKO/airflow/blob/master/dags/email_xcom_test.py 전 포스팅 내용을 기반으로 DAG을 만들었다. email_operator = EmailOperator( task_id='send_email', to='receiver@example.com', subject='[TEST] 테스트 메일입니다.', html_content=""" 테스트 메일입니다. ninja template {{ data_interval_start }} {{ ds }} {{ task_instance.xcom_pull(dag_id='postgres..

Airflow 2022.03.18

Airflow BranchSQLOperator 활용

apache/airflow github commit을 활용했다. https://github.com/apache/airflow/blob/39e395f9816c04ef2f033eb0b4f635fc3018d803/airflow/operators/sql.py#L470 활용한 전체 소스코드는 github에 올렸다. https://github.com/GHGHGHKO/airflow/blob/master/dags/postgres_test.py Airflow에서 제공하는 BranchSQLOperator를 활용한 예제이다. 쿼리의 결과(true or false)에 따라 TAG를 활용 할 수 있다. 추후 이 예시를 통해 테이블 스페이스가 가득 찰 경우 알람 메일이 전송되는 스케줄을 등록 할 것이다. true_branch_o..

Airflow 2022.03.14

Docker Airflow Oracle 활용하기

Apache Airflow, Oracle 공식 문서를 토대로 진행하고자 한다. https://airflow.apache.org/docs/apache-airflow-providers-oracle/stable/index.html https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html 아직 Airflow를 설치하지 않았다면 아래 글을 참고한 뒤 오면 좋다 https://pepega.tistory.com/44 dockerhub에 이미지를 올려뒀다. https://hub.docker.com/r/gudrb963/oracle-airflow 설치 시작 1. docker-compose에 환경변수 추가 _PIP_ADDITIONAL_REQUIREMEN..

Airflow 2022.03.10