-
Notifications
You must be signed in to change notification settings - Fork 0
/
dag_dnb_recommendation_reason_dev_all_parallel_new_account.py
96 lines (79 loc) · 2.04 KB
/
dag_dnb_recommendation_reason_dev_all_parallel_new_account.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
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
"""
DEV codes
"""
from __future__ import print_function
import time
from builtins import range
import airflow
from airflow.models import DAG
from airflow.operators.python_operator import PythonOperator,BranchPythonOperator
from airflow.operators.dummy_operator import DummyOperator
import os,sys
sys.path.insert(0,os.path.abspath(os.path.dirname(__file__)))
from dnb.header import *
from dnb.utils import *
from dnb import reason_lib as rslib
args = {
'owner': 'Airflow',
'depends_on_past': False,
'start_date': datetime.datetime(2019, 12, 27),
}
dag_id = 'dnb_recommendation_reason_dev_all_parallel_new_account'
dag_cap_lst = [ c[0] for c in dag_id.split('_') if c ]
dag_cap = ''
dag_cap = [dag_cap+c.upper() for c in dag_cap_lst]
"""
Create a DAG to execute tasks
"""
dag = DAG(
dag_id=dag_id,
default_args=args,
schedule_interval=None,
)
main_op = DummyOperator(
task_id='Main_entrance',
dag=dag,
)
# main_op = PythonOperator(
# task_id = 'Main_entrance',
# python_callable = rslib.prod_prepare_data,
# dag= dag,
# )
end_op = DummyOperator(
task_id = 'End',
trigger_rule = 'none_failed',
dag = dag,
)
prev_city_op_tail = main_op
merging_all_op = PythonOperator(
task_id='merging_all',
python_callable=rslib.data_merge_for_all_cities_new_account,
trigger_rule = 'all_done',
dag=dag,
)
for ind_city in range(len(citylongname)):
# if citylongname[ind_city] != 'San Francisco':
# continue
"""
task of each city
Each city will run in sequence
Execution module
"""
task_exe_id = cityabbr[ind_city] + '_exe'
exe_op = PythonOperator(
task_id=task_exe_id,
provide_context=True,
python_callable=rslib.prod_all_reason_in_one_func,
op_kwargs={
'ind_city': ind_city,
'is_account_new':True,
},
dag=dag,
)
main_op >> exe_op >> merging_all_op
# prev_city_op_tail >> exe_op
# prev_city_op_tail = exe_op
#
#
# prev_city_op_tail >> merging_all_op >> end_op
merging_all_op >> end_op