Skip to content

Commit

Permalink
Catch caching issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
antarcticrainforest committed Aug 12, 2024
1 parent 27c0626 commit f4ad88b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
13 changes: 10 additions & 3 deletions django_evaluation/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Collection of utility functions."""

from __future__ import annotations
import logging

import json
import threading
Expand Down Expand Up @@ -43,9 +44,15 @@ def sync_mail_users(refresh_itervall: int = 3600, oneshot: bool = False) -> None
email__isnull=True
)
]
cache.set(
"user_email_info", mark_safe(json.dumps(user_info)), refresh_itervall + 10
)
try:
cache.set(
"user_email_info",
mark_safe(json.dumps(user_info)),
refresh_itervall + 10,
)
except Exception as error:
logger = logging.getLogger("freva-web")
logger.error("Could not add user email info to cache: %s", error)
if oneshot is True:
break
time.sleep(refresh_itervall)
9 changes: 8 additions & 1 deletion history/templatetags/dialogtags.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import json

from django import template
Expand Down Expand Up @@ -35,7 +36,13 @@ def mailfield(is_guest):
"""Extract the email information from users that have been logged in."""
data = mark_safe(json.dumps([]))
if not is_guest:
data = cache.get("user_email_info") or mark_safe(
try:
data = cache.get("user_email_info")
except Exception as error:
data = None
logger = logging.getLogger("freva-web")
logger.error("Could not add user email info to cache: %s", error)
data = data or mark_safe(
json.dumps(
[
{
Expand Down

0 comments on commit f4ad88b

Please sign in to comment.