-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_01.py
56 lines (39 loc) · 1.22 KB
/
example_01.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from datetime import datetime
from airflow import DAG
from airflow.operators.dummy import DummyOperator
from airflow.operators.bash import BashOperator
from airflow.operators.python import PythonOperator
from airflow.models import BaseOperator
from airflow.utils.decorators import apply_defaults
dag = DAG(
dag_id='example_dag_01',
start_date=datetime(2024,10,17),
schedule_interval='@daily'
)
start = DummyOperator(task_id='start', dag=dag)
end = DummyOperator(task_id='end', dag=dag)
bash_task = BashOperator(
task_id='run_bash_command',
bash_command='echo "Hello, Airflow (bash)"',
dag = dag
)
def print_string():
print("Hello, Airflow (python)")
python_task = PythonOperator(
task_id='run_python_function',
python_callable=print_string,
dag=dag
)
class CustomOperator(BaseOperator):
@apply_defaults
def __init__(self, param, *args, **kwargs):
super(CustomOperator, self).__init__(*args, **kwargs)
self.param = param
def execute(self, context):
print(f"Custom Operator : {param}")
custom_task = CustomOperator(
task_id='run_custom_task',
param="Hello, Airflow (custom)",
dag=dag
)
start >> bash_task >> python_task >> custom_task >> end