-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4_xcoms_dag.py
65 lines (49 loc) · 2 KB
/
4_xcoms_dag.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
57
58
59
60
61
62
63
64
65
from airflow.models import DAG
from airflow.operators.dummy import DummyOperator
from airflow.operators.python import PythonOperator
from airflow.operators.bash import BashOperator
from datetime import datetime
NAME_LIST = ['Tinmar','Alejandra','Kenya','Atocha','Francisco','Paola','Lucy','Ajna']
default_args = {
"owner":"Tinmar",
"start_date": datetime(2023, 1, 9)
}
# PythonOperator: prueba_python
def xcom_push(*args, **context):
for palabra in args:
print(f'Hola {palabra}')
ti = context['ti']
ti.xcom_push(key='xcom_prueba', value='valor_de_prueba')
return 'Este es un Xcom'
def xcom_pull(**context):
ti = context['ti']
valor_recibido = ti.xcom_pull(task_ids='xcom_push')
valor_selecciondado = ti.xcom_pull(task_ids='xcom_push',key='xcom_prueba')
print(valor_recibido, valor_selecciondado)
with DAG(
'4_xcoms_dag',
catchup = False,
default_args=default_args,
schedule_interval=None,
tags=['Curso 2', 'Apache_Airflow']
) as dag:
start_task = DummyOperator(task_id='start_task')
prueba_push = PythonOperator(
task_id='xcom_push',
python_callable=xcom_push,
op_args=NAME_LIST,
provide_context=True,
do_xcom_push=True
)
prueba_pull = PythonOperator(
task_id='xcom_pull',
python_callable=xcom_pull,
provide_context=True,
do_xcom_push=True
)
prueba_bash = BashOperator(
task_id='bash_op',
bash_command='echo Prueba Bash'
)
end_task = DummyOperator(task_id='end_task')
start_task >> prueba_push >> prueba_pull >> prueba_bash >> end_task