@@ 8-35 (lines=28) @@ | ||
5 | import schedule |
|
6 | ||
7 | ||
8 | 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 analog 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_analog_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 | ||
37 | ||
38 | def process(logger): |
@@ 8-35 (lines=28) @@ | ||
5 | import schedule |
|
6 | ||
7 | ||
8 | 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 | ||
37 | ||
38 | def process(logger): |