-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
On Willow notifications run in a task. Starting such a task when there is already a task running causes undefined behaviour. We therefore want to avoid this situation. At the same time, we don't want a user to miss an important notification, so we cannot simply drop a notification if there is already an active notification. Enter NotifyQueue. Instead of passing a notification received on the API to Willow clients directly, we add them in a queue. This queue is a dict, with key being the MAC address of the Willow client. We cannot use the WebSocket as key, like we do in ConnMgr, as this changes every time Willow reconnects. And since we're on 2.4GHz Wi-Fi, reconnections will occur. NotifyQueue creates an asyncio task that loops forever, with a 1s delay between iterations. If a notification is queued for a client, there is no active notification, and the notification ID (UNIX timestamp in ms) is not in the future, the notification will be sent, and the client will be marked having an active notification. When the notification is done, Willow sends a notify_done to WAS, and WAS cleans up the notification from the queue. One problem with this approach is that if Willow is restarted or crashes during a notification, the notification will never be cleaned up in WAS. Another problem is that when a long running notification is active, important notifications like a timer or an alarm will not be sent. A solution for this could be to have notification priorities: if a notification is active, and a notification with a higher priority arrives, we cancel the running notification and start the new one. One more problem is that we don't have persistent state, so restarting WAS will result in the queued notifications being lost. We want this to be reliable, as people might use this for an alarm clock. Missing an alarm might result in someone getting in trouble at work. Missing a timer while cooking might result in having to throw away food.
- Loading branch information
Showing
1 changed file
with
109 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters