fixed interval settings
This commit is contained in:
parent
6b173495af
commit
ba8778cc3f
@ -1,7 +1,7 @@
|
||||
# Version: 1.7.0
|
||||
|
||||
# Constants for the notification system
|
||||
NOTIFICATION_COOLDOWN = 600 # 10 minutes until a notification gets real
|
||||
NOTIFICATION_COOLDOWN_MINS = 10 # until a notification gets real and cannot be deleted anymore
|
||||
NOTIFICATION_MAX_AGE_DAYS = 3 # 3 days until a notification gets deleted
|
||||
|
||||
# Placeholder for the email credentials filled by startup logic
|
||||
|
||||
@ -55,7 +55,7 @@ def UpdateShipcalls(options:dict = {'past_days':2}):
|
||||
logging.error(ex)
|
||||
return
|
||||
|
||||
def UpdateNotifications():
|
||||
def UpdateNotifications(cooldown_in_mins:int=10):
|
||||
"""
|
||||
This function evaluates all notifications in state ("level") 0 which have been recently created. If a specified amount of time has passed the
|
||||
notification is updated to state 1 and a notification is received by the user
|
||||
@ -65,7 +65,7 @@ def UpdateNotifications():
|
||||
pooledConnection = getPoolConnection()
|
||||
commands = pydapper.using(pooledConnection)
|
||||
|
||||
query = "SELECT * FROM notification WHERE level = 0 AND created < TIMESTAMP(NOW() - INTERVAL 10 MINUTE)"
|
||||
query = f"SELECT * FROM notification WHERE level = 0 AND created < TIMESTAMP(NOW() - INTERVAL {cooldown_in_mins} MINUTE)"
|
||||
data = commands.query(query, model=model.Notification)
|
||||
for notification in data:
|
||||
commands.execute("UPDATE notification SET level = 1 WHERE id = ?id?", param={"id":notification.id})
|
||||
@ -74,16 +74,16 @@ def UpdateNotifications():
|
||||
except Exception as ex:
|
||||
logging.error(ex)
|
||||
|
||||
def ClearNotifications():
|
||||
def ClearNotifications(max_age_in_days:int=3):
|
||||
"""
|
||||
This function clears all notifications in state ("level") 2 that are older than 3 days
|
||||
This function clears all notifications in state ("level") 2 that are older than x days
|
||||
"""
|
||||
|
||||
try:
|
||||
pooledConnection = getPoolConnection()
|
||||
commands = pydapper.using(pooledConnection)
|
||||
|
||||
query = "DELETE FROM notification WHERE level = 2 and created < TIMESTAMP(NOW() - INTERVAL 3 DAY)"
|
||||
query = f"DELETE FROM notification WHERE level = 2 and created < TIMESTAMP(NOW() - INTERVAL {max_age_in_days} DAY)"
|
||||
result = commands.execute(query)
|
||||
pooledConnection.close()
|
||||
if(result > 0):
|
||||
@ -259,14 +259,14 @@ def add_function_to_schedule__update_shipcalls(interval_in_minutes:int, options:
|
||||
return
|
||||
|
||||
def add_function_to_evaluate_notifications(interval_in_minutes:int=1):
|
||||
schedule.every(interval_in_minutes).minutes.do(UpdateNotifications)
|
||||
schedule.every(1).minutes.do(UpdateNotifications, interval_in_minutes)
|
||||
return
|
||||
|
||||
def add_function_to_clear_notifications(interval_in_minutes:int=60):
|
||||
schedule.every(interval_in_minutes).minutes.do(ClearNotifications)
|
||||
def add_function_to_clear_notifications(interval_in_days:int=3):
|
||||
schedule.every(30).minutes.do(ClearNotifications, interval_in_days)
|
||||
return
|
||||
|
||||
def add_function_to_schedule_send_notifications(interval_in_minutes:int=10):
|
||||
def add_function_to_schedule_send_notifications(interval_in_minutes:int=1):
|
||||
schedule.every(interval_in_minutes).minutes.do(SendNotifications)
|
||||
return
|
||||
|
||||
@ -313,9 +313,9 @@ def setup_schedule(update_shipcalls_interval_in_minutes:int=60):
|
||||
# update the evaluation state in every recent shipcall
|
||||
add_function_to_schedule__update_shipcalls(update_shipcalls_interval_in_minutes)
|
||||
|
||||
add_function_to_evaluate_notifications()
|
||||
add_function_to_evaluate_notifications(defs.NOTIFICATION_COOLDOWN_MINS)
|
||||
|
||||
add_function_to_clear_notifications()
|
||||
add_function_to_clear_notifications(defs.NOTIFICATION_MAX_AGE_DAYS)
|
||||
|
||||
schedule.every().day.at("09:00").do(eval_next_24_hrs)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user