터칭 데이터
Airflow - 커맨드 라인에서 Variables와 Connections 세팅 본문
커맨드 라인에서 Airflow 로그인
https://touchingdata.tistory.com/198
Airflow 기본 프로그램 실행
Airflow 코드의 기본 구조 DAG 대표하는 객체를 먼저 만듬 - DAG 이름, 실행주기, 실행날짜, 오너 등의 여러 파라미터를 지정 다음으로 DAG를 구성하는 태스크들을 만듬 - 태스크별로 적합한 오퍼레이
touchingdata.tistory.com
지난 시간 "2. 터미널로 연결해서 커맨드라인 툴 사용해보기"에서 Airflow를 사용하는 방법을 알아봤습니다.
1. docker ps를 입력해 scheduler의 스케줄러 컨테이너 ID를 찾는다.
2. docker exec -it (스케줄러의 컨테이너 ID) sh를 입력해 airflow에 로그인한다.
지난 시간 git clone으로 다운 받은 DAGs 조회
(airflow)ls -tl
total 64
drwxrwxrwx 1 root root 4096 Dec 13 09:24 logs
drwxrwxrwx 1 root root 4096 Dec 13 08:36 dags
-rw-r--r-- 1 airflow root 3 Dec 13 08:15 airflow-webserver.pid
-rw-rw-r-- 1 airflow root 51337 Dec 12 06:38 airflow.cfg
-rw-rw-r-- 1 airflow root 4771 Dec 12 06:38 webserver_config.py
drwxrwxrwx 1 root root 4096 Dec 12 06:37 plugins
로그인 후 ls -tl로 dags 폴더의 존재를 확인하실 수 있습니다.
(airflow)ls -tl dags
(DAGs 목록들..)
ls -tl dags로 dags 디렉토리를 살펴보면 DAG들을 조회하실 수 있습니다. 이는 지난 시간 git clone으로 다운 받고 airflow-setup 디렉토리의 dags로 복사, 붙여 넣기한 내용들이 Sync되어 있기 때문입니다.
일반적인 DAGs 목록 조회
(airflow)airflow dags list
(생략..)
name_gender | NameGenderCSVtoRedshift.py | airflow | True
name_gender_v2 | NameGenderCSVtoRedshift_v2.py | airflow | False
name_gender_v3 | NameGenderCSVtoRedshift_v3.py | airflow | True
name_gender_v4 | NameGenderCSVtoRedshift_v4.py | airflow | False
namegender_v5 | NameGenderCSVtoRedshift_v5.py | airflow | True
(생략..)
맨 우측의 True, False는 paused 여부입니다. 바로 이전 시간 Web UI에서 Connections와 Variables를 세팅할 때 v2와 v4만 실행했던 것 기억하시죠?
특정 DAG의 task(태스크) 목록 조회
(airflow)airflow tasks list namegender_v5
extract
load
transform
Variables 명령어
(airflow)airflow variables
usage: airflow variables [-h] COMMAND ...
Manage variables
positional arguments:
COMMAND
delete Delete variable
export Export all variables
get Get variable
import Import variables
list List variables
set Set variable
optional arguments:
-h, --help show this help message and exit
airflow variables command error: the following arguments are required: COMMAND, see help above.
airflow variables를 입력하시면 여러 기능들과 설명이 출력됩니다.
(airflow)airflow variables list
key
=======
csv_url
airflow variables list를 사용하면 모든 variables를 조회할 수 있습니다. 이전에 만든 csv_url이 보이네요.
(airflow)airflow variables get csv_url
/home/airflow/.local/lib/python3.7/site-packages/airflow/models/base.py:49 MovedIn20Warning: [31mDeprecated API features detected! These feature(s) are not compatible with SQLAlchemy 2.0. [32mTo prevent incompatible upgrades prior to updating applications, ensure requirements files are pinned to "sqlalchemy<2.0". [36mSet environment variable SQLALCHEMY_WARN_20=1 to show all deprecation warnings. Set environment variable SQLALCHEMY_SILENCE_UBER_WARNING=1 to silence this message.[0m (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
https://s3-geospatial.s3-us-west-2.amazonaws.com/name_gender.csv
airflow variables get (variable ID)로 조회할 수 있습니다.
다른 명령어도 살펴보자면 export로 variables를 json 형태로 다운 받아 백업, 공유도 가능합니다.
'Airflow' 카테고리의 다른 글
Airflow - Yahoo Finance API Full Refresh (0) | 2023.12.13 |
---|---|
Airflow 관련 기타 Q&A (0) | 2023.12.13 |
Airflow - Web UI로 Variables와 Connections 세팅 (0) | 2023.12.13 |
Airflow - Redshift Connection 설정 & Decorators (0) | 2023.12.13 |
Airflow - Name Gender 예제 프로그램 포팅 (0) | 2023.12.13 |