Cache key does not match, what problem could it be?
zN3utr4l opened this issue · comments
Hi, I've been using this library for a while, I created a celery task that runs every day at every hour sends an email if one of the checks fails.
It's always the "Cache Backend" that fails, but what do you mean it's not ok? why the check on the "Database Backend" is successful?
I'm having some problems with celery, I was trying to implement gevent for a performance optimization because with the base pool it eats too much ram and I'm afraid it will close my processes at random, running everything on Docker.
I cannot access the pc on which this healthy check is installed, I can only do it via VNC, remotely, and very often I notice that after the email arrives with the failing cache, the pc is no longer reachable via VNC, as if was crashed or frozen.
I opened a question about on stackoverflow but got no answer:
https://stackoverflow.com/questions/76357078/synchronousonlyoperation-from-celery-task-using-gevent-execution-pool-on-django
The cache backend is trying to set a key and get that key. If it's not able to do so, it will raise an exception.
try:
cache.set(self.cache_key, "itworks")
if not cache.get(self.cache_key) == "itworks":
raise ServiceUnavailable(f"Cache key {self.cache_key} does not match")
should print self.cache_key
, but it just writes Cache key does not match
. Could it be that it hasn't set any keys?
Yes, that is correct
ok but then the problem is not that he hasn't set any key to db, but that self.cache_key has no value
The value of the key is shown in the code above. "itworks" is the value being set to "self.cache_key".
ok but why the error is Cache key does not match? it could be Cache key djangohealthcheck_test does not match
self.cache_key could be djangohealthcheck_test.
maybe self.cache_key has no value, i didn't set HEALTHCHECK_CACHE_KEY in my django project
self.cache_key = getattr(
settings, "HEALTHCHECK_CACHE_KEY", "djangohealthcheck_test"
)
It's saying that the value of the cache key does not match what was supposed to have been set, it's not trying to list the key's name at all.
You don't need to set it, by default it uses the key "djangohealthcheck_test".
Based on the issues you're describing at the top of the post:
- You don't have Django's caching framework configured at all, if that is the case then you should not include the cache health check as it's always going to fail.
- You do have cache setup, but it's configuration is broken or the cache (Redis, memcache, etc.) is not running