-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrotate_portal_activity_data.py
44 lines (34 loc) · 1.43 KB
/
rotate_portal_activity_data.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
# coding: utf-8
#!/usr/bin/env python
from Utils import *
from ConfigUtils import *
from PostgresStuff import *
from PandasUtils import *
from MonitorPortal import *
def rotateActivityData(conn):
#drop the chunks on the hyper table that are older than two weeks
rotate_qry = """
SELECT drop_chunks(interval '2 weeks', 'portal_activity');
"""
dropped_chunks = PostgresStuff.commitQry(conn, rotate_qry)
return dropped_chunks
def main():
curr_full_path = FileUtils.getCurrentDirFullPath()
config_fn = 'portal_activity_job_config.yaml'
cI = ConfigUtils(curr_full_path+ "/configs/" , config_fn)
configItems = cI.getConfigs()
configItems['config_dir'] = curr_full_path+ "/" + configItems['config_dir']
configItems['curr_full_path'] = curr_full_path
db_ini = configItems['config_dir'] + configItems['database_config']
conn_alq, meta_alq =PostgresStuff.connect_alq(db_ini)
conn = PostgresStuff.connect(db_ini)
db_tbl = configItems['activity_table']
rotate_items = rotateActivityData(conn)
activity = "rotate_portal_activity"
subject_line = configItems['activity'][activity]['email_msg']['subject_line']
msg_body = configItems['email_msg_template']['header'] + configItems['activity'][activity]['email_msg']['msg']
msg_body = msg_body + configItems['email_msg_template']['footer']
em = Emailer(configItems)
em.sendEmails(subject_line, msg_body.encode('utf-8').strip())
if __name__ == "__main__":
main()