-
Notifications
You must be signed in to change notification settings - Fork 0
/
airflow
129 lines (84 loc) · 2.62 KB
/
airflow
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# primeira Dag Airflow
from airflow import DAG
from airflow.operators.python_operator import PythonOperator
from airflow.operators.bash_operator import BashOperator
from datetime import datetime, timedelta
import pandas as pd
# Argumentos default
default_args = {
'owner': 'Marcio Santana',
'depends_on_past': False,
'start_date': datetime(2020, 11, 15, 15),
'email': ['[email protected]'],
'email_on_failure': False,
'email_on_retry': False,
"retries":1,
"retry_delay":timedelta(minutes=1)
}
dag = DAG(
"treino-02",
description="Extrai dado do Titanic da internet e calcula idade media dos passageiros",
default_args = default_args,
schedule_interval=timedelta(minutes=2)
)
get_data = BashOperator(
task_id = 'get-data',
bash_command = 'curl https://raw.githubusercontente.com/A3Data/hermione/master/hermione/file_text/train.csv -o ~/train.csv',
dag = dag
)
def calculate_mean_age():
df = pd.read_csv('~/train.csv')
med = df.Age.mean()
return med
def print_age(** context):
value = context['task_instance'].xcom_pull(task_ids= 'calcula-idade-media')
print(f"A idade media do titanic era {value} anos.")
task_idade_media = PythonOperator(
task_id= 'calcula-idade-media',
python_callable = calculate_mean_age,
dag = dag
)
task_print_idade = PythonOperator(
task_id = 'mostra-idade',
python_callble = print_age,
dag = dag
)
get_data >> task_idade_media >> task_print_idade
########### primeiro arquivo##################
# primeira Dag Airflow
from airflow import DAG
from airflow.operators.python_operator import PythonOperator
from airflow.operators.bash_operator import BashOperator
from datetime import datetime, timedelta
# Argumentos default
default_args = {
'owner': 'Marcio Santana',
'depends_on_past': False,
'start_date': datetime(2020, 11, 15, 15),
'email': ['[email protected]'],
'email_on_failure': False,
'email_on_retry': False,
"retries":1,
"retry_delay":timedelta(minutes=1)
}
# vamos definir a Dag - fluxo
dag = DAG(
"treino-01",
description="Basico de Bash Operators e python Operators",
default_args = default_args,
schedule_interval=timedelta(minutes=2)
)
# vamos começar a adicionar tarefas
hello_bash = BashOperator(
task_id = "Hello_Bash",
bash_command= 'echo "Hello Airflow from basch"',
dag = dag
)
def say_hello():
print("Hello Airflow from python") # funcao
hello_python = PythonOperator(
task_id = "Hello Python",
python_callable=say_hello,
dag=dag
)
hello_bash >> hello_python # ordenando a sequencia