Repository: mozilla/telemetry-analysis-service

Issue:
Email server shutdown warning again after extending cluster
Hey, would it be possible to send another hour warning email if a user extends the cluster life?


Discussion:
cc: @jezdez 
This seems like a good idea but I'm afraid ATMO feature development is on hold while Redash and STMO take the majority of our time. Rest assured when we get back to ATMO we'll schedule working on this.

Resolving patch:
diff --git a/atmo/clusters/models.py b/atmo/clusters/models.py
--- a/atmo/clusters/models.py
+++ b/atmo/clusters/models.py
@@ -360,6 +360,7 @@ def extend(self, hours):
         """Extend the cluster lifetime by the given number of hours."""
         self.expires_at = models.F('expires_at') + timedelta(hours=hours)
         self.lifetime_extension_count = models.F('lifetime_extension_count') + 1
+        self.expiration_mail_sent = False
         self.save()
 
         with transaction.atomic():


Test patch:
diff --git a/requirements/tests.txt b/requirements/tests.txt
--- a/requirements/tests.txt
+++ b/requirements/tests.txt
@@ -61,10 +61,9 @@ pytest-django==3.4.4 \
 pytest-mock==1.10.0 \
     --hash=sha256:53801e621223d34724926a5c98bd90e8e417ce35264365d39d6c896388dcc928 \
     --hash=sha256:d89a8209d722b8307b5e351496830d5cc5e192336003a485443ae9adeb7dd4c0
-pycodestyle==2.4.0 \
-    --hash=sha256:74abc4e221d393ea5ce1f129ea6903209940c1ecd29e002e8c6933c2b21026e0 \
-    --hash=sha256:cbc619d09254895b0d12c2c691e237b2e91e9b2ecf5e84c26b35400f93dcfb83 \
-    --hash=sha256:cbfca99bd594a10f674d0cd97a3d802a1fdef635d4361e1a2658de47ed261e3a # pyup: <2.4.0,>=2.0.0
+pycodestyle==2.3.1 \
+    --hash=sha256:682256a5b318149ca0d2a9185d365d8864a768a28db66a84a2ea946bcc426766 \
+    --hash=sha256:6c4245ade1edfad79c3446fadfc96b0de2759662dc29d07d80a6f27ad1ca6ba9 # pyup: <2.4.0,>=2.0.0
 freezegun==0.3.10 \
     --hash=sha256:94c59d69bb99c9ec3ca5a3adb41930d3ea09d2a9756c23a02d89fa75646e78dd \
     --hash=sha256:703caac155dcaad61f78de4cb0666dca778d854dfb90b3699930adee0559a622
diff --git a/tests/clusters/test_tasks.py b/tests/clusters/test_tasks.py
--- a/tests/clusters/test_tasks.py
+++ b/tests/clusters/test_tasks.py
@@ -200,3 +200,42 @@ def test_update_clusters(mocker, now, user, cluster_factory):
             'size': cluster3.size
         })
     ]
+
+
+def test_extended_cluster_resends_expiration_mail(mailoutbox, mocker, one_hour_ago, cluster_factory):
+    cluster = cluster_factory(
+        expires_at=one_hour_ago,
+        most_recent_status=models.Cluster.STATUS_WAITING,
+    )
+
+    # Send first expiration email
+    assert len(mailoutbox) == 0
+    tasks.send_expiration_mails()
+    assert len(mailoutbox) == 1
+    message = mailoutbox[0]
+    assert message.subject == (
+        '%sCluster %s is expiring soon!' %
+        (settings.EMAIL_SUBJECT_PREFIX, cluster.identifier)
+    )
+    assert message.from_email == settings.DEFAULT_FROM_EMAIL
+    assert list(message.to) == [cluster.created_by.email]
+    cluster.refresh_from_db()
+    assert cluster.expiration_mail_sent
+
+    # Extend cluster lifetime
+    cluster.extend(1)
+    cluster.refresh_from_db()
+    assert cluster.expiration_mail_sent is False
+
+    # Send second expiration email
+    tasks.send_expiration_mails()
+    assert len(mailoutbox) == 2
+    message = mailoutbox[1]
+    assert message.subject == (
+        '%sCluster %s is expiring soon!' %
+        (settings.EMAIL_SUBJECT_PREFIX, cluster.identifier)
+    )
+    assert message.from_email == settings.DEFAULT_FROM_EMAIL
+    assert list(message.to) == [cluster.created_by.email]
+    cluster.refresh_from_db()
+    assert cluster.expiration_mail_sent