Airflow 10

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 OracleOperator Custom 하기

공식 문서를 기반으로 작성하였다. PostgresHook https://airflow.apache.org/docs/apache-airflow-providers-oracle/stable/_modules/airflow/providers/oracle/hooks/oracle.html#OracleHook DbApi https://airflow.apache.org/docs/apache-airflow/stable/_modules/airflow/hooks/dbapi.html#DbApiHook.get_first 하단 코드는 아래에 있다. https://github.com/GHGHGHKO/airflow/commit/47de1fd55ff2be812702ba4539adf54e6d9bd292 OracleOperator 사용 할..

Airflow 2022.03.17

Airflow PostgresOperator Custom 하기

공식 문서를 기반으로 작성하였다. PostgresHook https://airflow.apache.org/docs/apache-airflow-providers-postgres/stable/_api/airflow/providers/postgres/hooks/postgres/index.html#airflow.providers.postgres.hooks.postgres.PostgresHook.conn_name_attr DbApi https://airflow.apache.org/docs/apache-airflow/stable/_modules/airflow/hooks/dbapi.html#DbApiHook.get_first 하단 코드는 아래에 있다. https://github.com/GHGHGHKO/airflow/..

Airflow 2022.03.17

Airflow custom Operator 만들기

공식 문서를 기반으로 글과 코드를 작성하였다. https://airflow.apache.org/docs/apache-airflow/stable/howto/custom-operator.html 코드는 아래에 있다. https://github.com/GHGHGHKO/airflow/commit/37966fd4e8774e04c95f6393fd796b86573d4dc2 예시를 들어서 내용을 적도록 하겠다. 테이블 스페이스가 부족할 때 경고 메일을 보내는 스케줄을 추가하려고 한다. 메일 내용에 특정 테이블 스페이스 이름을 넣은 채로 메일을 보내고 싶은데 --테이블 스페이스 이름 조회 select name from table_space; Airflow에서 제공하는 SQLOperator는 Airflow의 XCOM으로 ..

Airflow 2022.03.16

Airflow 메일 전송, EmailOperator, SMTP, Gmail

airflow.cfg EmailOperator Gmail 활용하였다. 관련 코드 https://github.com/GHGHGHKO/airflow/blob/master/dags/mail_test.py airflow.cfg [smtp] 설정 문서 https://airflow.apache.org/docs/apache-airflow/stable/configurations-ref.html#config-smtp EmailOperator https://airflow.apache.org/docs/apache-airflow/stable/_api/airflow/operators/email/index.html Gmail SMTP 활용 https://support.google.com/mail/answer/7126229?hl=..

Airflow 2022.03.15

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

Docker Airflow 설치하기

Apache Airflow 공식 문서를 토대로 진행하고자 한다. https://airflow.apache.org/docs/apache-airflow/stable/start/docker.html 로컬에서 진행할 예정이다. 공식 문서에 따르면 프로덕션 환경에서 사용하기 위한 것이 아니라고 나온다. 그래서 추후에 "Kubernetes 기반의 Airflow 활용하기"를 올릴 예정이다. 설치 후 원하고자 하는 활용 방안은 아래와 같다. 1. 테이블 조회 후 일정 수치 이상일 경우 알람 메일 발송 2. 서버 피크시간(09시~18시) 이후 매달 초 다량의 데이터를 메일로 전송 설치 시작 1. docker-compose 파일 설치 curl -LfO 'https://airflow.apache.org/docs/apache..

Airflow 2022.03.09