From 631bf325204b0925adfa133e21956377c4815411 Mon Sep 17 00:00:00 2001 From: Sho Okada Date: Mon, 2 Mar 2020 16:21:24 +0900 Subject: [PATCH] Fix race condition --- promgen/tasks.py | 4 ++++ promgen/views.py | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/promgen/tasks.py b/promgen/tasks.py index ef3b9a796..6dcf71120 100644 --- a/promgen/tasks.py +++ b/promgen/tasks.py @@ -43,6 +43,10 @@ def process_alert(alert_pk): alert.delete() return + # After processing our blacklist, it should be safe to queue our + # alert to also index the labels + index_alert.delay(alert.pk) + # Now that we have our routable items, we want to check which senders are # configured and expand those as needed senders = collections.defaultdict(set) diff --git a/promgen/views.py b/promgen/views.py index 15b808273..24cd6c4cf 100644 --- a/promgen/views.py +++ b/promgen/views.py @@ -1019,7 +1019,6 @@ def post(self, request, *args, **kwargs): # when we run tasks.process_alert alert = models.Alert.objects.create(body=request.body.decode("utf-8")) tasks.process_alert.delay(alert.pk) - tasks.index_alert.delay(alert.pk) return HttpResponse("OK", status=202)