mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 18:36:36 +00:00
[manual] Rename Django app from zephyr to zerver.
This needs to be deployed to both staging and prod at the same off-peak time (and the schema migration run). At the time it is deployed, we need to make a few changes directly in the database: (1) UPDATE django_content_type set app_label='zerver' where app_label='zephyr'; (2) UPDATE south_migrationhistory set app_name='zerver' where app_name='zephyr'; (imported from commit eb3fd719571740189514ef0b884738cb30df1320)
This commit is contained in:
50
zerver/lib/logging_util.py
Normal file
50
zerver/lib/logging_util.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import logging
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
# Adapted http://djangosnippets.org/snippets/2242/ by user s29 (October 25, 2010)
|
||||
|
||||
class _RateLimitFilter(object):
|
||||
last_error = datetime.min
|
||||
|
||||
def filter(self, record):
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
|
||||
# Track duplicate errors
|
||||
duplicate = False
|
||||
rate = getattr(settings, '%s_LIMIT' % self.__class__.__name__.upper(),
|
||||
600) # seconds
|
||||
if rate > 0:
|
||||
# Test if the cache works
|
||||
try:
|
||||
cache.set('RLF_TEST_KEY', 1, 1)
|
||||
use_cache = cache.get('RLF_TEST_KEY') == 1
|
||||
except:
|
||||
use_cache = False
|
||||
|
||||
if use_cache:
|
||||
key = self.__class__.__name__.upper()
|
||||
duplicate = cache.get(key) == 1
|
||||
cache.set(key, 1, rate)
|
||||
else:
|
||||
min_date = datetime.now() - timedelta(seconds=rate)
|
||||
duplicate = (self.last_error >= min_date)
|
||||
if not duplicate:
|
||||
self.last_error = datetime.now()
|
||||
|
||||
return not duplicate
|
||||
|
||||
class HumbugLimiter(_RateLimitFilter):
|
||||
pass
|
||||
|
||||
class EmailLimiter(_RateLimitFilter):
|
||||
pass
|
||||
|
||||
class ReturnTrue(logging.Filter):
|
||||
def filter(self, record):
|
||||
return True
|
||||
|
||||
class RequireReallyDeployed(logging.Filter):
|
||||
def filter(self, record):
|
||||
from django.conf import settings
|
||||
return settings.DEPLOYED and not settings.TESTING_DEPLOYED
|
||||
Reference in New Issue
Block a user