Skip to content

Commit 53e29d3

Browse files
authored
Merge pull request #109 from monzo/mattrco/incident-close-nudge
Periodically remind incident lead to close incident
2 parents a6db7a8 + 565b9a6 commit 53e29d3

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

response/slack/decorators/incident_notification.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import time
2-
import requests
31
import logging
42

53
from datetime import datetime
64

75
from response.core.models import Incident
8-
from response.slack.models.comms_channel import CommsChannel
96
from response.slack.models.notification import Notification
107

118
logger = logging.getLogger(__name__)
@@ -62,7 +59,8 @@ def _wrapper(fn):
6259

6360

6461
def handle_notifications():
65-
# notifications are only sent to open incidents with comms channels
62+
63+
# Only notify open incidents with a comms channel
6664
open_incidents = Incident.objects.filter(
6765
end_time__isnull=True,
6866
commschannel__incident__isnull=False
@@ -84,8 +82,8 @@ def handle_notifications():
8482
if mins_since_last_notify >= handler.interval_mins:
8583
try:
8684
handler.callback(incident)
87-
except:
88-
logger.error(f"Error calling notification handler {handler}")
85+
except Exception as e:
86+
logger.error(f"Error calling notification handler {handler}: {e}")
8987

9088
notification.time = datetime.now()
9189
notification.repeat_count = notification.repeat_count + 1
@@ -98,8 +96,8 @@ def handle_notifications():
9896
if mins_since_started >= handler.interval_mins:
9997
try:
10098
handler.callback(incident)
101-
except:
102-
logger.error(f"Error calling notification handler {handler}")
99+
except Exception as e:
100+
logger.error(f"Error calling notification handler {handler}: {e}")
103101

104102
notification = Notification(
105103
incident=incident,
Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from datetime import datetime
2+
13
from response.core.models import Incident
24
from response.slack.models import CommsChannel
35
from response.slack .decorators import recurring_notification, single_notification
@@ -8,7 +10,8 @@ def remind_severity(incident: Incident):
810
try:
911
comms_channel = CommsChannel.objects.get(incident=incident)
1012
if not incident.severity:
11-
comms_channel.post_in_channel("🌤️ This incident doesn't have a severity. Please set one with `@incident severity ...`")
13+
comms_channel.post_in_channel(
14+
"🌤️ This incident doesn't have a severity. Please set one with `@incident severity ...`")
1215
except CommsChannel.DoesNotExist:
1316
pass
1417

@@ -18,15 +21,25 @@ def remind_incident_lead(incident: Incident):
1821
try:
1922
comms_channel = CommsChannel.objects.get(incident=incident)
2023
if not incident.lead:
21-
comms_channel.post_in_channel("👩‍🚒 This incident hasn't got a lead. Please set one with `@incident lead ...`")
24+
comms_channel.post_in_channel(
25+
"👩‍🚒 This incident hasn't got a lead. Please set one with `@incident lead ...`")
2226
except CommsChannel.DoesNotExist:
2327
pass
2428

25-
@recurring_notification(interval_mins=720, max_notifications=6)
29+
30+
@recurring_notification(interval_mins=1440, max_notifications=5)
2631
def remind_close_incident(incident: Incident):
32+
33+
# Only remind on weekdays (weekday returns an ordinal indexed from 0 on Monday)
34+
if datetime.now().weekday() in (5, 6):
35+
return
36+
2737
try:
2838
comms_channel = CommsChannel.objects.get(incident=incident)
2939
if not incident.is_closed():
30-
comms_channel.post_in_channel(":timer_clock: This incident has been running a long time. Can it be closed now? Remember to pin important messages in order to create the timeline.")
40+
user_to_notify = incident.lead or incident.reporter
41+
comms_channel.post_in_channel(
42+
f":timer_clock: <@{user_to_notify.external_id}>, this incident has been running a long time."
43+
" Can it be closed now? Remember to pin important messages in order to create the timeline.")
3144
except CommsChannel.DoesNotExist:
32-
pass
45+
pass

0 commit comments

Comments
 (0)