the evaluation function (traffic-light validation) additionally performs the notification function to generate notifications. Integrated within the scheduler.
This commit is contained in:
parent
b078386520
commit
0de0baf1d4
@ -76,6 +76,9 @@ class Notifier():
|
|||||||
# create an Email and send it to each eligible_user.
|
# create an Email and send it to each eligible_user.
|
||||||
# #TODO: this method must be a distributor. It should send emails for those, who want emails, and provide placeholders for other types of notifications
|
# #TODO: this method must be a distributor. It should send emails for those, who want emails, and provide placeholders for other types of notifications
|
||||||
Notifier.create_and_send_email_notification(email_handler, mail_pwd, eligible_users, notification, update_database=update_database, debug=debug)
|
Notifier.create_and_send_email_notification(email_handler, mail_pwd, eligible_users, notification, update_database=update_database, debug=debug)
|
||||||
|
|
||||||
|
# #TODO: except... logging?
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
email_handler.close()
|
email_handler.close()
|
||||||
return
|
return
|
||||||
@ -334,14 +337,34 @@ class Notifier():
|
|||||||
looking up its history, and finding all attached users.
|
looking up its history, and finding all attached users.
|
||||||
For each user, a notification will be created for each subscribed notification type (e.g., Email)
|
For each user, a notification will be created for each subscribed notification type (e.g., Email)
|
||||||
"""
|
"""
|
||||||
# get the respective shipcall
|
|
||||||
shipcall = Notifier.get_shipcall(shipcall_id)
|
shipcall = Notifier.get_shipcall(shipcall_id)
|
||||||
|
notifications = execute_sql_query_standalone(query=SQLQuery.get_notifications(), param={"scid" : shipcall_id}, model=model.Notification, command_type="query")
|
||||||
|
latest_notification = Notifier.find_latest_notification(notifications)
|
||||||
|
|
||||||
# find all attached users of the shipcall (checks the history, then reads out the user ids and builds the users)
|
old_state = model.EvaluationType(latest_notification.level) if latest_notification is not None else model.EvaluationType.undefined
|
||||||
users = Notifier.get_users_via_history(shipcall_id=shipcall.id)
|
new_state = shipcall.evaluation
|
||||||
|
|
||||||
# for each user, create one notification for each subscribed notification type (e.g., Email)
|
# identify, whether the severity of the shipcall has increased to see, whether a notification is required
|
||||||
Notifier.create_notifications_for_user_list(shipcall, users)
|
severity_increase = Notifier.check_higher_severity(old_state=old_state, new_state=new_state)
|
||||||
|
|
||||||
|
# when the severity increases, set the 'evaluation_notifications_sent' argument to 0 (False)
|
||||||
|
if severity_increase:
|
||||||
|
### UPDATE Shipcall ###
|
||||||
|
# prepare and create a query
|
||||||
|
evaluation_notifications_sent = 0
|
||||||
|
schemaModel = {"id":shipcall.id, "evaluation_notifications_sent":evaluation_notifications_sent} # #TODO: should this require the 'modified' tag to be adapted?
|
||||||
|
query = SQLQuery.get_shipcall_put(schemaModel)
|
||||||
|
|
||||||
|
# execute the PUT-Request
|
||||||
|
schemas = execute_sql_query_standalone(query=query, param=schemaModel, command_type="execute")
|
||||||
|
|
||||||
|
### Generate Notifications ###
|
||||||
|
# find all attached users of the shipcall (checks the history, then reads out the user ids and builds the users)
|
||||||
|
users = Notifier.get_users_via_history(shipcall_id=shipcall.id)
|
||||||
|
|
||||||
|
# for each user, identify the notification_types, which must be generated. Finally, create those
|
||||||
|
# notifications with a POST-request
|
||||||
|
Notifier.create_notifications_for_user_list(shipcall, users)
|
||||||
return
|
return
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@ -39,6 +39,7 @@ def UpdateShipcalls(options:dict = {'past_days':2}):
|
|||||||
for shipcall_id in shipcall_ids:
|
for shipcall_id in shipcall_ids:
|
||||||
# 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=shipcall_id) # new_id (last insert id) refers to the shipcall id
|
evaluate_shipcall_state(mysql_connector_instance=pooledConnection, shipcall_id=shipcall_id) # new_id (last insert id) refers to the shipcall id
|
||||||
|
Notifier.generate_notifications(shipcall_id)
|
||||||
|
|
||||||
pooledConnection.close()
|
pooledConnection.close()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user