Add retry-safe scan completion notifications

This commit is contained in:
Joren de Graaf
2026-10-26 01:57:24 +01:00
parent 0e4077d8e3
commit 31266b1533
5 changed files with 68 additions and 11 deletions
+7 -4
View File
@@ -9,11 +9,14 @@ class NotificationError(Exception):
"""A delivery error safe to display without exposing the topic URL."""
def send_ntfy_notification(url, title, message, timeout=10):
def send_ntfy_notification(url, title, message, timeout=10, sequence_id=None):
headers = {'Content-Type': 'text/plain; charset=utf-8', 'Title': title}
if sequence_id:
headers['X-Sequence-ID'] = str(sequence_id)[:64]
request = Request(
url,
data=message.encode('utf-8'),
headers={'Content-Type': 'text/plain; charset=utf-8', 'Title': title},
headers=headers,
method='POST',
)
try:
@@ -29,9 +32,9 @@ def send_ntfy_notification(url, title, message, timeout=10):
raise NotificationError(f'ntfy server responded with HTTP {status}.')
def send_notification(user, title, message):
def send_notification(user, title, message, *, sequence_id=None):
preferences = UserSettings.objects.filter(user=user).first()
if not preferences or not preferences.ntfy_enabled or not preferences.ntfy_url:
return False
send_ntfy_notification(preferences.ntfy_url, title, message)
send_ntfy_notification(preferences.ntfy_url, title, message, sequence_id=sequence_id)
return True