from airflow import DAG
from datetime import datetime
with DAG(
='example_dag',
dag_id='@daily',
schedule=datetime(2022, 4, 5),
start_date=False,
catchupas dag:
) pass
Coding pipeline
Air flow
DAG skeleton
- DAG는 start_date / last_execution time + schedule_interval에 실행된다.
Operator
- operator 하나 당 하나의 task만 실행하는게 좋다.
operator type
- Action operators
- BashOperator
- PythonOperator
- Transfer operators
- Sensor operators
Providers
- Airflow providers are a set of packages that contain operators, sensors, hooks, and other utilities to interact with external platforms and services.
- Providers are installed separately from Airflow and can be added to your environment as needed.
- In Airflow core, Bash and Python operators, … are included
from airflow.providers.postgres.operators.postgres import PostgresOperator
with DAG(
='example_db',
dag_id='@daily',
schedule=datetime(2022, 4, 5),
start_date=False,
catchupas dag:
) = PostgresOperator(
create_table ='create_table',
task_id='postgres',
postgres_conn_id="""
sql CREATE TABLE IF NOT EXISTS example_table (
id SERIAL PRIMARY KEY,
name VARCHAR(50)
);
""",
)
- DB에 접속하기 위해서 connection을 설정해야 한다.