Fix telegram retrying task after alert group was deleted (#3546)

# What this PR does

## Which issue(s) this PR fixes
https://github.com/grafana/oncall-private/issues/2379

## Checklist

- [ ] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)

---------

Co-authored-by: Joey Orlando <joey.orlando@grafana.com>
This commit is contained in:
Yulya Artyukhina 2023-12-11 19:06:04 +01:00 committed by GitHub
parent 0d959a5c20
commit 8a56b2273b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View file

@ -1,4 +1,5 @@
import json
import pytest
from django.urls import reverse
from rest_framework import status

View file

@ -226,8 +226,19 @@ def on_alert_group_action_triggered_async(log_record_id):
from .alert_group_representative import AlertGroupTelegramRepresentative
logger.info(f"AlertGroupTelegramRepresentative ACTION SIGNAL, log record {log_record_id}")
log_record = AlertGroupLogRecord.objects.get(pk=log_record_id)
# temporary solution to handle cases when alert group and related log records were deleted
try:
log_record = AlertGroupLogRecord.objects.get(pk=log_record_id)
except AlertGroupLogRecord.DoesNotExist as e:
retries_count = on_alert_group_action_triggered_async.request.retries
if retries_count >= 10:
logger.error(
f"AlertGroupTelegramRepresentative: was not able to get AlertGroupLogRecord, probably alert group "
f"was deleted. log record {log_record_id}, retries: {retries_count}"
)
return
else:
raise e
instance = AlertGroupTelegramRepresentative(log_record)
if instance.is_applicable():