Conditions | 7 |
Total Lines | 28 |
Code Lines | 24 |
Lines | 28 |
Ratio | 100 % |
Changes | 0 |
1 | import mysql.connector |
||
8 | View Code Duplication | def job(logger): |
|
|
|||
9 | |||
10 | cnx = None |
||
11 | cursor = None |
||
12 | try: |
||
13 | cnx = mysql.connector.connect(**config.myems_historical_db) |
||
14 | cursor = cnx.cursor() |
||
15 | except Exception as e: |
||
16 | logger.error("Error in clean digital value process " + str(e)) |
||
17 | if cursor: |
||
18 | cursor.close() |
||
19 | if cnx: |
||
20 | cnx.close() |
||
21 | return |
||
22 | |||
23 | expired_utc = datetime.utcnow() - timedelta(days=config.live_in_days) |
||
24 | try: |
||
25 | cursor.execute(" DELETE FROM tbl_digital_value WHERE utc_date_time < %s ", (expired_utc,)) |
||
26 | cnx.commit() |
||
27 | except Exception as e: |
||
28 | logger.error("Error in delete_expired_trend process " + str(e)) |
||
29 | finally: |
||
30 | if cursor: |
||
31 | cursor.close() |
||
32 | if cnx: |
||
33 | cnx.close() |
||
34 | |||
35 | logger.info("Deleted trend before date time in UTC: " + expired_utc.isoformat()[0:19]) |
||
36 | |||
51 |