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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218 | import os
import sys
# for airflow subfolder, when no module named
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from datetime import timedelta, datetime
from airflow.operators.python_operator import PythonOperator
from airflow.models import DAG
from cloudengine.utils.common import config, failure_callback
from cloudengine.ods import extract
from cloudengine.dwd.dim_pvmah_icsr import dim_pvmah_icsr
from cloudengine.dwd.dim_pvmah_icsr_drug import dim_pvmah_icsr_drug
from cloudengine.dwd.dim_pvmah_patient import dim_pvmah_patient
from cloudengine.dwd.dwd_pvmah_reaction_event import dwd_pvmah_reaction_event
from cloudengine.dwd.dwd_pvmah_query_field_info import dwd_pvmah_query_field_info
from cloudengine.dws.dws_pvmah_event_amount__am import dws_pvmah_event_amount__am
from cloudengine.dws.dws_pvmah_icsr_amount__am import dws_pvmah_icsr_amount__am
from cloudengine.dws.dws_pvmah_icsr_task_status_amount__aa import dws_pvmah_icsr_task_status_amount__aa
from cloudengine.dws.dws_pvmah_module_query_amount__aa import dws_pvmah_module_query_amount__aa
from cloudengine.dws.dws_pvmah_query_amount__am import dws_pvmah_query_amount__am
from cloudengine.ads.ads_pvmah_icsr_task_status_amount__aa import ads_pvmah_icsr_task_status_amount__aa
from cloudengine.ads.ads_pvmah_module_query_amount__aa import ads_pvmah_module_query_amount__aa
from cloudengine.ads.ads_pvmah_query_amount__am import ads_pvmah_query_amount__am
from cloudengine.ads.ads_pvmah_event_amount__am import ads_pvmah_event_amount__am
from cloudengine.ads.ads_pvmah_icsr_amount__am import ads_pvmah_icsr_amount__am
from cloudengine.utils.tableau.refresh_data import tableau_data_extract
error_inform = config['email_list']['error_inform']
error_inform_list = error_inform.split(',')
default_args = {
'owner': 'airflow',
'depends_on_past': False,
'start_date': datetime(2020, 9, 2),
'email': error_inform_list,
'email_on_failure': True,
'email_on_retry': False,
'retries': 2,
'retry_delay': timedelta(minutes=2),
'provide_context': False,
# 'queue': 'bash_queue',
# 'pool': 'backfill',
# 'priority_weight': 10,
# 'schedule_interval': '20 16 * * *',
# 'end_date': datetime(2018, 4, 14),
}
default_args['on_failure_callback'] = failure_callback
CONF_SECTION = "airflow_schedule"
pvmah_board_flow_interval = config[CONF_SECTION]['pvmah_board_flow']
pvmah_board_flow_dag = DAG('pvmah_board_flow', default_args=default_args,
schedule_interval=pvmah_board_flow_interval)
####### ods level
def level_load():
pass
task_ods_level = PythonOperator(
task_id='ods_level_load',
python_callable=level_load,
dag=pvmah_board_flow_dag)
def pvmah_ods_load():
extract.extract_group("pvmah")
task_ods_pvmah = PythonOperator(
task_id='ods_pvmah',
python_callable=pvmah_ods_load,
dag=pvmah_board_flow_dag)
#### dim level
def dim_level_load():
pass
task_dim_level = PythonOperator(
task_id='dim_level_load',
python_callable=level_load,
dag=pvmah_board_flow_dag)
task_dim_pvmah_icsr = PythonOperator(
task_id='dim_pvmah_icsr',
python_callable=dim_pvmah_icsr.process,
dag=pvmah_board_flow_dag)
task_dim_pvmah_patient = PythonOperator(
task_id='dim_pvmah_patient',
python_callable=dim_pvmah_patient.process,
dag=pvmah_board_flow_dag)
task_dim_pvmah_icsr_drug = PythonOperator(
task_id='dim_pvmah_icsr_drug',
python_callable=dim_pvmah_icsr_drug.process,
dag=pvmah_board_flow_dag)
#### dwd level
def dwd_level_load():
pass
task_dwd_level = PythonOperator(
task_id='dwd_level_load',
python_callable=level_load,
dag=pvmah_board_flow_dag)
task_dwd_pvmah_reaction_event = PythonOperator(
task_id='dwd_pvmah_reaction_event',
python_callable=dwd_pvmah_reaction_event.process,
dag=pvmah_board_flow_dag)
task_dwd_pvmah_query_field_info = PythonOperator(
task_id='dwd_pvmah_query_field_info',
python_callable=dwd_pvmah_query_field_info.process,
dag=pvmah_board_flow_dag)
def dws_level_load():
pass
#### dws level
task_dws_level = PythonOperator(
task_id='dws_level_load',
python_callable=level_load,
dag=pvmah_board_flow_dag)
task_dws_pvmah_event_amount__am = PythonOperator(
task_id='dws_pvmah_event_amount__am',
python_callable=dws_pvmah_event_amount__am.process,
dag=pvmah_board_flow_dag)
task_dws_pvmah_icsr_amount__am = PythonOperator(
task_id='dws_pvmah_icsr_amount__am',
python_callable=dws_pvmah_icsr_amount__am.process,
dag=pvmah_board_flow_dag)
task_dws_pvmah_icsr_task_status_amount__aa = PythonOperator(
task_id='dws_pvmah_icsr_task_status_amount__aa',
python_callable=dws_pvmah_icsr_task_status_amount__aa.process,
dag=pvmah_board_flow_dag)
task_dws_pvmah_module_query_amount__aa = PythonOperator(
task_id='dws_pvmah_module_query_amount__aa',
python_callable=dws_pvmah_module_query_amount__aa.process,
dag=pvmah_board_flow_dag)
task_dws_pvmah_query_amount__am = PythonOperator(
task_id='dws_pvmah_query_amount__am',
python_callable=dws_pvmah_query_amount__am.process,
dag=pvmah_board_flow_dag)
#### ads level
def ads_level_load():
pass
task_ads_level = PythonOperator(
task_id='ads_level_load',
python_callable=level_load,
dag=pvmah_board_flow_dag)
task_ads_pvmah_icsr_task_status_amount__aa = PythonOperator(
task_id='ads_pvmah_icsr_task_status_amount__aa',
python_callable=ads_pvmah_icsr_task_status_amount__aa.process,
dag=pvmah_board_flow_dag)
task_ads_pvmah_module_query_amount__aa = PythonOperator(
task_id='ads_pvmah_module_query_amount__aa',
python_callable=ads_pvmah_module_query_amount__aa.process,
dag=pvmah_board_flow_dag)
task_ads_pvmah_query_amount__am = PythonOperator(
task_id='ads_pvmah_query_amount__am',
python_callable=ads_pvmah_query_amount__am.process,
dag=pvmah_board_flow_dag)
task_ads_pvmah_event_amount__am = PythonOperator(
task_id='ads_pvmah_event_amount__am',
python_callable=ads_pvmah_event_amount__am.process,
dag=pvmah_board_flow_dag)
task_ads_pvmah_icsr_amount__am = PythonOperator(
task_id='ads_pvmah_icsr_amount__am',
python_callable=ads_pvmah_icsr_amount__am.process,
dag=pvmah_board_flow_dag)
#### report level
def report_level_load():
pass
task_report_level = PythonOperator(
task_id='report_level_load',
python_callable=level_load,
dag=pvmah_board_flow_dag)
#### tableau_data_extract
def tableau_data_extract_pvmah():
refresh_data = tableau_data_extract("pvmah_board_flow")
refresh_data.run_job()
task_tableau_data_extract = PythonOperator(
task_id='tableau_data_extract_pvmah',
python_callable=tableau_data_extract_pvmah,
dag=pvmah_board_flow_dag)
task_ods_level >> [task_ods_pvmah] >> task_dim_level >> [
task_dim_pvmah_icsr, task_dim_pvmah_patient, task_dim_pvmah_icsr_drug] >> task_dwd_level >> [
task_dwd_pvmah_reaction_event, task_dwd_pvmah_query_field_info] >> task_dws_level >> [
task_dws_pvmah_icsr_task_status_amount__aa, task_dws_pvmah_module_query_amount__aa, task_dws_pvmah_query_amount__am, task_dws_pvmah_event_amount__am, task_dws_pvmah_icsr_amount__am] >> task_ads_level >> [
task_ads_pvmah_icsr_task_status_amount__aa, task_ads_pvmah_module_query_amount__aa, task_ads_pvmah_query_amount__am, task_ads_pvmah_event_amount__am, task_ads_pvmah_icsr_amount__am] >> task_report_level >> task_tableau_data_extract
|