From eef9bf05cd6cf50c9c1e3479aa69695997e1b6f5 Mon Sep 17 00:00:00 2001 From: Rebecca Cremona Date: Mon, 8 Jan 2024 15:12:27 -0500 Subject: [PATCH 1/3] Email admins when a casebook's export fails the max allowed times. --- web/main/models.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/web/main/models.py b/web/main/models.py index c48827b70..22f4f31b3 100644 --- a/web/main/models.py +++ b/web/main/models.py @@ -63,6 +63,7 @@ prefix_ids_hrefs, rich_text_export, strip_trailing_block_level_whitespace, + send_mail ) @@ -3470,7 +3471,17 @@ def export( def inc_export_fails(self): # This function is used to avoid making a copy of the casebook via CasebookHistory + orig = self.export_fails Casebook.objects.filter(id=self.id).update(export_fails=F("export_fails") + 1) + self.refresh_from_db() + if orig < settings.MAX_EXPORT_ATTEMPTS and self.export_fails >= settings.MAX_EXPORT_ATTEMPTS: + message = f"Export of casebook {self.id} ({self.title}) has failed the maximum allowed times.\n\nPlease investigate, and reset to zero if the failures were spurious." + send_mail( + f"Export of H2O Casebook {self.id} is frozen.", + message, + settings.DEFAULT_FROM_EMAIL, + settings.ADMINS, + ) def reset_export_fails(self): # This function is used to avoid making a copy of the casebook via CasebookHistory From 7f65306092f722db7330d5c3b15e7bf0d85a02e5 Mon Sep 17 00:00:00 2001 From: Rebecca Cremona Date: Mon, 8 Jan 2024 15:13:13 -0500 Subject: [PATCH 2/3] Allow five sequential export errors, instead of 3. --- web/config/settings/settings_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/config/settings/settings_base.py b/web/config/settings/settings_base.py index e882e414a..37f751c76 100644 --- a/web/config/settings/settings_base.py +++ b/web/config/settings/settings_base.py @@ -300,7 +300,7 @@ class LoggerConfig(TypedDict, total=False): "secret_key": "secretkey", } -MAX_EXPORT_ATTEMPTS = 3 +MAX_EXPORT_ATTEMPTS = 5 MAX_EXPORTS_PER_HOUR = 600 EXPORT_RATE_FALLOFF = int(MAX_EXPORTS_PER_HOUR / 60) From 64981a346421a502a7d161a178e3ddaa5065b623 Mon Sep 17 00:00:00 2001 From: Rebecca Cremona Date: Mon, 8 Jan 2024 15:18:35 -0500 Subject: [PATCH 3/3] Reformat how Black likes it. --- web/main/models.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/web/main/models.py b/web/main/models.py index 22f4f31b3..2faaeaadf 100644 --- a/web/main/models.py +++ b/web/main/models.py @@ -63,7 +63,7 @@ prefix_ids_hrefs, rich_text_export, strip_trailing_block_level_whitespace, - send_mail + send_mail, ) @@ -3474,7 +3474,10 @@ def inc_export_fails(self): orig = self.export_fails Casebook.objects.filter(id=self.id).update(export_fails=F("export_fails") + 1) self.refresh_from_db() - if orig < settings.MAX_EXPORT_ATTEMPTS and self.export_fails >= settings.MAX_EXPORT_ATTEMPTS: + if ( + orig < settings.MAX_EXPORT_ATTEMPTS + and self.export_fails >= settings.MAX_EXPORT_ATTEMPTS + ): message = f"Export of casebook {self.id} ({self.title}) has failed the maximum allowed times.\n\nPlease investigate, and reset to zero if the failures were spurious." send_mail( f"Export of H2O Casebook {self.id} is frozen.",