Skip to content

Busy lab notification

Marina Mădăraş requested to merge busy-lab-notification into development

Closes #691, #372

About

Made this in such a way that there is a method that polls every 10 minutes and checks if there is a lab that has finished within the last 15 minutes, and if there is, it checks if it was busy (in @LabService). The condition we have, for now decided to mark whether a lab was busy or not is:

if for a lab, it has >= 20 requests AND at least 10% of requests had a waiting time of >= 30mins

The waiting time in this context is then is the difference between time the request was first processed/ or the current time if it was never processed and the creation time of the request (for normal labs) or the slot starting time (for slotted labs).

Then, a websocket message is sent to the client side, for each of the members of the staff (Teacher and head TA), which indicates that there is an unread notification for the user. If the client is still connected, upon receiving this message, they send a https request to the server to get the unread notification(s) for the authenticated user. Upon sending them, if they are received by the client, they are marked as read with a timestamp, so as to not display them again.

But, if the user is not "online", then we still store the notifications, and when they log in, upon DOMContentLoaded we check if they have unread notifications. If they have any, we send them to the client, where they get aggregated into a singular one so as to not bother the user too much.

Disclaimers (for which ideas are very much welcome 😄 ):

  1. I don't think on sending a request each time on DOMContentLoaded to check if there are unread notifications is ideal, but I tried to reuse the logic from @LabService in @QueueUserHandler, on login. What I noticed however is that if you log in after logging out, the websockets get disconnected sometimes, and then we risk the notifications appearing sometime randomly in the future.
  2. The way the notifications look is largely due to the general nature of how I structured the Notification class, so as to be able to reuse it in the future and make it somehow easily aggregate-able. But, if you have ideas how to make the notification look prettier tell me.

How to test the MR

So, in the state that it is rn, it is very long to test whether this works as a whole feature. There are unit and integration tests, also especially for the long waiting time condition. How I checked that everything worked, except the actually verifying the long waiting time condition explained at the beginning, is within the method @checkIfRecentlyFinishedLabBusy in @LabService, I changed the @Scheduled(cron = "0 */10 * * * *") in @Scheduled(cron = "0 * * * * *") to run every minute, not every 10 minutes AND by putting these two lines:

 String message = ns.createNotificationMessage(session.getName(), countOfLongRequests);
 ns.notifyStaffTheirLabWasBusy(editionId, message, lab.getId());

above the if check on line 689. And then just creating/ editing labs such that their end time is within the past 15 mins. (and also logging out in the process and logging back in).

image image

Edited by Marina Mădăraş

Merge request reports

Loading