Scheduler setup for notification level evaluation
This commit is contained in:
parent
9b69e4f50c
commit
573ab2d808
@ -139,6 +139,7 @@ def PostShipcalls(schemaModel):
|
|||||||
pquery = "INSERT INTO shipcall_participant_map (shipcall_id, participant_id, type) VALUES (?shipcall_id?, ?participant_id?, ?type?)"
|
pquery = "INSERT INTO shipcall_participant_map (shipcall_id, participant_id, type) VALUES (?shipcall_id?, ?participant_id?, ?type?)"
|
||||||
for participant_assignment in schemaModel["participants"]:
|
for participant_assignment in schemaModel["participants"]:
|
||||||
commands.execute(pquery, param={"shipcall_id" : new_id, "participant_id" : participant_assignment["participant_id"], "type" : participant_assignment["type"]})
|
commands.execute(pquery, param={"shipcall_id" : new_id, "participant_id" : participant_assignment["participant_id"], "type" : participant_assignment["type"]})
|
||||||
|
# TODO: Create assignment notification for each participant
|
||||||
|
|
||||||
# apply 'Traffic Light' evaluation to obtain 'GREEN', 'YELLOW' or 'RED' evaluation state. The function internally updates the mysql database
|
# apply 'Traffic Light' evaluation to obtain 'GREEN', 'YELLOW' or 'RED' evaluation state. The function internally updates the mysql database
|
||||||
# evaluate_shipcall_state(mysql_connector_instance=pooledConnection, shipcall_id=new_id) # new_id (last insert id) refers to the shipcall id
|
# evaluate_shipcall_state(mysql_connector_instance=pooledConnection, shipcall_id=new_id) # new_id (last insert id) refers to the shipcall id
|
||||||
@ -249,11 +250,14 @@ def PutShipcalls(schemaModel):
|
|||||||
for participant_assignment in schemaModel["participants"]:
|
for participant_assignment in schemaModel["participants"]:
|
||||||
if(participant_assignment["participant_id"] == elem["participant_id"] and participant_assignment["type"] == elem["type"]):
|
if(participant_assignment["participant_id"] == elem["participant_id"] and participant_assignment["type"] == elem["type"]):
|
||||||
found_participant = True
|
found_participant = True
|
||||||
|
# TODO: Create assignment notification
|
||||||
|
|
||||||
break;
|
break;
|
||||||
if not found_participant:
|
if not found_participant:
|
||||||
# dquery = SQLQuery.get_shipcall_participant_map_delete_by_id()
|
# dquery = SQLQuery.get_shipcall_participant_map_delete_by_id()
|
||||||
dquery = "DELETE FROM shipcall_participant_map WHERE id = ?existing_id?"
|
dquery = "DELETE FROM shipcall_participant_map WHERE id = ?existing_id?"
|
||||||
commands.execute(dquery, param={"existing_id" : elem["id"]})
|
commands.execute(dquery, param={"existing_id" : elem["id"]})
|
||||||
|
# TODO: Create un-assignment notification
|
||||||
|
|
||||||
# save history data
|
# save history data
|
||||||
# TODO: set ETA properly
|
# TODO: set ETA properly
|
||||||
|
|||||||
@ -45,11 +45,34 @@ def UpdateShipcalls(options:dict = {'past_days':2}):
|
|||||||
logging.error(ex)
|
logging.error(ex)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def UpdateNotifications():
|
||||||
|
"""
|
||||||
|
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
|
||||||
|
"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
pooledConnection = getPoolConnection()
|
||||||
|
commands = pydapper.using(pooledConnection)
|
||||||
|
|
||||||
|
query = "SELECT * FROM notification WHERE level = 0 AND created < DATE(NOW() - INTERVAL 10 MINUTES)"
|
||||||
|
data = commands.query(query, model=model.Notification)
|
||||||
|
for notification in data:
|
||||||
|
notification.level = 1
|
||||||
|
commands.update(notification)
|
||||||
|
pooledConnection.close()
|
||||||
|
except Exception as ex:
|
||||||
|
logging.error(ex)
|
||||||
|
|
||||||
def add_function_to_schedule__update_shipcalls(interval_in_minutes:int, options:dict={'past_days':2}):
|
def add_function_to_schedule__update_shipcalls(interval_in_minutes:int, options:dict={'past_days':2}):
|
||||||
kwargs_ = {"options":options}
|
kwargs_ = {"options":options}
|
||||||
schedule.every(interval_in_minutes).minutes.do(UpdateShipcalls, **kwargs_)
|
schedule.every(interval_in_minutes).minutes.do(UpdateShipcalls, **kwargs_)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def add_function_to_evaluate_notifications(interval_in_minutes:int=1):
|
||||||
|
schedule.every(interval_in_minutes).minutes.do(UpdateNotifications)
|
||||||
|
return
|
||||||
|
|
||||||
def add_function_to_schedule__send_notifications(vr, interval_in_minutes:int=10):
|
def add_function_to_schedule__send_notifications(vr, interval_in_minutes:int=10):
|
||||||
schedule.every(interval_in_minutes).minutes.do(vr.notifier.send_notifications)
|
schedule.every(interval_in_minutes).minutes.do(vr.notifier.send_notifications)
|
||||||
return
|
return
|
||||||
@ -64,8 +87,11 @@ def setup_schedule(update_shipcalls_interval_in_minutes:int=60):
|
|||||||
# update the evaluation state in every recent shipcall
|
# update the evaluation state in every recent shipcall
|
||||||
add_function_to_schedule__update_shipcalls(update_shipcalls_interval_in_minutes)
|
add_function_to_schedule__update_shipcalls(update_shipcalls_interval_in_minutes)
|
||||||
|
|
||||||
|
add_function_to_evaluate_notifications()
|
||||||
|
|
||||||
# placeholder: create/send notifications
|
# placeholder: create/send notifications
|
||||||
# add_function_to_schedule__send_notifications(...)
|
# add_function_to_schedule__send_notifications(...)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user