From 0df8e14589fbdd1f944516f4f43a3f9559c0839c Mon Sep 17 00:00:00 2001 From: zakhy <=> Date: Mon, 17 Feb 2025 12:53:02 +0700 Subject: [PATCH] alarm --- apps/schedulers/tasks.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/schedulers/tasks.py b/apps/schedulers/tasks.py index 98ae181..49634c8 100644 --- a/apps/schedulers/tasks.py +++ b/apps/schedulers/tasks.py @@ -8,7 +8,7 @@ import math import requests.exceptions as rex -from django.db.models import Sum +from django.db.models import Sum, Min from django.core.cache import cache from django.db.models import Q @@ -587,6 +587,10 @@ def load_asd(): WHERE EventCountInMinute >= 3 """ + duplicates = GtoAlarm.objects.values('alarmid').annotate( + min_id=Min('id')).values('min_id') + GtoAlarm.objects.exclude(id__in=duplicates).delete() + cursor = connection.cursor() cursor.execute(sql_query)