|
1 | 1 | import os |
| 2 | +import time |
2 | 3 |
|
3 | 4 | from django.conf import settings |
4 | 5 | from django.core import checks |
@@ -52,14 +53,14 @@ def check_doc_email_aliases_exists(app_configs, **kwargs): |
52 | 53 | try: |
53 | 54 | ok = check_doc_email_aliases() |
54 | 55 | if not ok: |
55 | | - errors.append(checks.Critical( |
| 56 | + errors.append(checks.Error( |
56 | 57 | "Found no aliases in the document email aliases file\n'%s'."%settings.DRAFT_ALIASES_PATH, |
57 | 58 | hint="Please run ietf/bin/generate-draft-aliases to generate them.", |
58 | 59 | obj=None, |
59 | 60 | id="datatracker.E0004", |
60 | 61 | )) |
61 | 62 | except IOError as e: |
62 | | - errors.append(checks.Critical( |
| 63 | + errors.append(checks.Error( |
63 | 64 | "Could not read document email aliases:\n %s" % e, |
64 | 65 | hint="Please run ietf/bin/generate-draft-aliases to generate them.", |
65 | 66 | obj=None, |
@@ -176,4 +177,35 @@ def check_proceedings_directories(app_configs, **kwargs): |
176 | 177 | )) |
177 | 178 | return errors |
178 | 179 |
|
| 180 | +@checks.register('cache') |
| 181 | +def check_cache(app_configs, **kwargs): |
| 182 | + errors = [] |
| 183 | + if settings.SERVER_MODE == 'production': |
| 184 | + from django.core.cache import cache |
| 185 | + def cache_error(msg, errnum): |
| 186 | + return checks.Warning( |
| 187 | + ( "A cache test failed with the message:\n '%s'.\n" |
| 188 | + "This indicates that the cache is unavailable or not working as expected.\n" |
| 189 | + "It will impact performance, but isn't fatal. The default cache is:\n" |
| 190 | + " CACHES['default']['BACKEND'] = %s\n") % ( |
| 191 | + msg, |
| 192 | + settings.CACHES["default"]["BACKEND"], |
| 193 | + ), |
| 194 | + hint = "Please check that the configured cache backend is available.\n", |
| 195 | + id = "datatracker.%s" % errnum, |
| 196 | + ) |
| 197 | + key = "ietf:checks:check_cache" |
| 198 | + val = os.urandom(32) |
| 199 | + wait = 1 |
| 200 | + cache.set(key, val, wait) |
| 201 | + if not cache.get(key) == val: |
| 202 | + errors.append(cache_error("Could not get value from cache", "E0014")) |
| 203 | + time.sleep(wait+1) |
| 204 | + # should have timed out |
| 205 | + if cache.get(key) == val: |
| 206 | + errors.append(cache_error("Cache value didn't time out", "E0015")) |
| 207 | + cache.set(key, val, settings.SESSION_COOKIE_AGE) |
| 208 | + if not cache.get(key) == val: |
| 209 | + errors.append(cache_error("Cache didn't accept session cookie age", "E0016")) |
| 210 | + return errors |
179 | 211 |
|
0 commit comments