-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_02.py
More file actions
54 lines (36 loc) · 1.27 KB
/
example_02.py
File metadata and controls
54 lines (36 loc) · 1.27 KB
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
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
with DAG(
dag_id='example_dag_02',
start_date=datetime(2024,10,16),
schedule_interval='@daily'
) as dag:
start = DummyOperator(task_id='start')
end = DummyOperator(task_id='end')
bash_task = BashOperator(
task_id='run_bash_command',
bash_command='echo "Hello, Airflow (bash)"'
)
def print_string():
print("Hello, Airflow (python)")
python_task = PythonOperator(
task_id='run_python_function',
python_callable=print_string
)
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)"
)
start >> bash_task >> python_task >> custom_task >> end