##// END OF EJS Templates
fix(celery): use a lightweight method of db ping to speed up tasks executions
fix(celery): use a lightweight method of db ping to speed up tasks executions

File last commit:

r5288:c652fe5b default
r5290:2ffa4031 default
Show More
__init__.py
119 lines | 3.7 KiB | text/x-python | PythonLexer
copyrights: updated for 2023
r5088 # Copyright (C) 2015-2023 RhodeCode GmbH
caches: rewrite of auth/permission caches to dogpile.
r2845 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
caches: added logging for dogpile configuration.
r2885 import logging
caches: new updated rc_cache with archive cache module and python3 changes
r5067 import threading
caches: rewrite of auth/permission caches to dogpile.
r2845 from dogpile.cache import register_backend
caches: new updated rc_cache with archive cache module and python3 changes
r5067
from . import region_meta
from .utils import (
ActiveRegionCache,
InvalidationContext,
backend_key_generator,
clear_cache_namespace,
get_default_cache_settings,
get_or_create_region,
make_region,
str2bool,
)
rccache: refactor and update code to support latest dogpile code changes (mostly on custom serializers)
r4985 module_name = 'rhodecode'
caches: rewrite of auth/permission caches to dogpile.
r2845
register_backend(
rccache: refactor and update code to support latest dogpile code changes (mostly on custom serializers)
r4985 "dogpile.cache.rc.memory_lru", f"{module_name}.lib.rc_cache.backends",
caches: rewrite of auth/permission caches to dogpile.
r2845 "LRUMemoryBackend")
register_backend(
rccache: refactor and update code to support latest dogpile code changes (mostly on custom serializers)
r4985 "dogpile.cache.rc.file_namespace", f"{module_name}.lib.rc_cache.backends",
caches: rewrite of auth/permission caches to dogpile.
r2845 "FileNamespaceBackend")
register_backend(
rccache: refactor and update code to support latest dogpile code changes (mostly on custom serializers)
r4985 "dogpile.cache.rc.redis", f"{module_name}.lib.rc_cache.backends",
caches: rewrite of auth/permission caches to dogpile.
r2845 "RedisPickleBackend")
caches: synced cache logic with vcsserver.
r3851 register_backend(
rccache: refactor and update code to support latest dogpile code changes (mostly on custom serializers)
r4985 "dogpile.cache.rc.redis_msgpack", f"{module_name}.lib.rc_cache.backends",
caches: synced cache logic with vcsserver.
r3851 "RedisMsgPackBackend")
caches: rewrite of auth/permission caches to dogpile.
r2845
caches: added logging for dogpile configuration.
r2885 log = logging.getLogger(__name__)
caches: rewrite of auth/permission caches to dogpile.
r2845
caches: make sure the global cache namespace prefixes are used....
r5106 FILE_TREE_CACHE_VER = 'v5'
LICENSE_CACHE_VER = 'v3'
PERMISSIONS_CACHE_VER = 'v2'
cache: bump file-tree caches to next iteration
r4036
caches: new updated rc_cache with archive cache module and python3 changes
r5067 CLEAR_DELETE = 'delete'
CLEAR_INVALIDATE = 'invalidate'
chore(code-cleanups): fixed spelling on variable
r5196 def async_creation_runner(cache, cache_key, creator, mutex):
caches: new updated rc_cache with archive cache module and python3 changes
r5067
def runner():
try:
value = creator()
chore(code-cleanups): fixed spelling on variable
r5196 cache.set(cache_key, value)
caches: new updated rc_cache with archive cache module and python3 changes
r5067 finally:
mutex.release()
thread = threading.Thread(target=runner)
thread.start()
caches: rewrite of auth/permission caches to dogpile.
r2845 def configure_dogpile_cache(settings):
cache_dir = settings.get('cache_dir')
if cache_dir:
region_meta.dogpile_config_defaults['cache_dir'] = cache_dir
rc_cache_data = get_default_cache_settings(settings, prefixes=['rc_cache.'])
# inspect available namespaces
avail_regions = set()
for key in rc_cache_data.keys():
namespace_name = key.split('.', 1)[0]
core: speed up cache loading
r4594 if namespace_name in avail_regions:
continue
caches: rewrite of auth/permission caches to dogpile.
r2845
core: speed up cache loading
r4594 avail_regions.add(namespace_name)
log.debug('dogpile: found following cache regions: %s', namespace_name)
caches: rewrite of auth/permission caches to dogpile.
r2845 new_region = make_region(
core: speed up cache loading
r4594 name=namespace_name,
caches: new updated rc_cache with archive cache module and python3 changes
r5067 function_key_generator=None,
async_creation_runner=None
caches: rewrite of auth/permission caches to dogpile.
r2845 )
caches: new updated rc_cache with archive cache module and python3 changes
r5067 new_region.configure_from_config(settings, f'rc_cache.{namespace_name}.')
caches: synced cache logic with vcsserver.
r3851 new_region.function_key_generator = backend_key_generator(new_region.actual_backend)
caches: new updated rc_cache with archive cache module and python3 changes
r5067
async_creator = str2bool(settings.pop(f'rc_cache.{namespace_name}.async_creator', 'false'))
if async_creator:
log.debug('configuring region %s with async creator', new_region)
new_region.async_creation_runner = async_creation_runner
app: improve logging, and remove DB calls on app startup.
r4548 if log.isEnabledFor(logging.DEBUG):
caches: new updated rc_cache with archive cache module and python3 changes
r5067 region_args = dict(backend=new_region.actual_backend,
app: improve logging, and remove DB calls on app startup.
r4548 region_invalidator=new_region.region_invalidator.__class__)
caches: make sure the global cache namespace prefixes are used....
r5106 log.debug('dogpile: registering a new region key=`%s` args=%s', namespace_name, region_args)
app: improve logging, and remove DB calls on app startup.
r4548
core: speed up cache loading
r4594 region_meta.dogpile_cache_regions[namespace_name] = new_region
caches: rewrite of auth/permission caches to dogpile.
r2845
def includeme(config):
configure_dogpile_cache(config.registry.settings)