Clear notifications from the database that are more than 3 days in the past
This commit is contained in:
parent
cda3f231a7
commit
6b173495af
@ -74,6 +74,24 @@ def UpdateNotifications():
|
||||
except Exception as ex:
|
||||
logging.error(ex)
|
||||
|
||||
def ClearNotifications():
|
||||
"""
|
||||
This function clears all notifications in state ("level") 2 that are older than 3 days
|
||||
"""
|
||||
|
||||
try:
|
||||
pooledConnection = getPoolConnection()
|
||||
commands = pydapper.using(pooledConnection)
|
||||
|
||||
query = "DELETE FROM notification WHERE level = 2 and created < TIMESTAMP(NOW() - INTERVAL 3 DAY)"
|
||||
result = commands.execute(query)
|
||||
pooledConnection.close()
|
||||
if(result > 0):
|
||||
logging.info(f"Deleted {result} notifications")
|
||||
|
||||
except Exception as ex:
|
||||
logging.error(ex)
|
||||
|
||||
def SendEmails(email_dict):
|
||||
"""
|
||||
This function sends emails to all users in the emaildict
|
||||
@ -244,6 +262,10 @@ def add_function_to_evaluate_notifications(interval_in_minutes:int=1):
|
||||
schedule.every(interval_in_minutes).minutes.do(UpdateNotifications)
|
||||
return
|
||||
|
||||
def add_function_to_clear_notifications(interval_in_minutes:int=60):
|
||||
schedule.every(interval_in_minutes).minutes.do(ClearNotifications)
|
||||
return
|
||||
|
||||
def add_function_to_schedule_send_notifications(interval_in_minutes:int=10):
|
||||
schedule.every(interval_in_minutes).minutes.do(SendNotifications)
|
||||
return
|
||||
@ -293,6 +315,8 @@ def setup_schedule(update_shipcalls_interval_in_minutes:int=60):
|
||||
|
||||
add_function_to_evaluate_notifications()
|
||||
|
||||
add_function_to_clear_notifications()
|
||||
|
||||
schedule.every().day.at("09:00").do(eval_next_24_hrs)
|
||||
|
||||
add_function_to_schedule_send_notifications(1)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user