Skip to content

Commit

Permalink
Merge pull request #2035 from rebeccacremona/alert-frozen-textbooks
Browse files Browse the repository at this point in the history
Notify admins when a book's export has failed many times
  • Loading branch information
rebeccacremona authored Jan 8, 2024
2 parents f10ec73 + 64981a3 commit 64b3233
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion web/config/settings/settings_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
14 changes: 14 additions & 0 deletions web/main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
prefix_ids_hrefs,
rich_text_export,
strip_trailing_block_level_whitespace,
send_mail,
)


Expand Down Expand Up @@ -3470,7 +3471,20 @@ 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
Expand Down

0 comments on commit 64b3233

Please sign in to comment.