mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-23 18:04:34 +00:00
fix
This commit is contained in:
@@ -327,10 +327,10 @@ class CloudPlatform(osv.osv_abstract):
|
|||||||
"Redis must be activated on prod, integration, labs,"
|
"Redis must be activated on prod, integration, labs,"
|
||||||
" test instances. This is done by setting ODOO_SESSION_REDIS=1."
|
" test instances. This is done by setting ODOO_SESSION_REDIS=1."
|
||||||
)
|
)
|
||||||
assert os.environ.get("ODOO_SESSION_REDIS_HOST") or os.environ.get(
|
assert os.environ.get("ODOO_SESSION_REDIS_URL") or os.environ.get(
|
||||||
"ODOO_SESSION_REDIS_SENTINEL_HOST"
|
"ODOO_SESSION_REDIS_SENTINEL_URL"
|
||||||
), (
|
), (
|
||||||
"ODOO_SESSION_REDIS_HOST or ODOO_SESSION_REDIS_SENTINEL_HOST "
|
"ODOO_SESSION_REDIS_URL or ODOO_SESSION_REDIS_SENTINEL_URL "
|
||||||
"environment variable is required to connect on Redis"
|
"environment variable is required to connect on Redis"
|
||||||
)
|
)
|
||||||
assert os.environ.get("ODOO_SESSION_REDIS_PREFIX"), (
|
assert os.environ.get("ODOO_SESSION_REDIS_PREFIX"), (
|
||||||
|
|||||||
+35
-27
@@ -24,45 +24,45 @@ except ImportError:
|
|||||||
|
|
||||||
|
|
||||||
def is_true(strval):
|
def is_true(strval):
|
||||||
return bool(strtobool(strval or '0'.lower()))
|
return bool(strtobool(strval or "0".lower()))
|
||||||
|
|
||||||
|
|
||||||
sentinel_host = os.environ.get('ODOO_SESSION_REDIS_SENTINEL_HOST')
|
sentinel_host = os.environ.get("ODOO_SESSION_REDIS_SENTINEL_HOST")
|
||||||
sentinel_master_name = os.environ.get(
|
sentinel_master_name = os.environ.get("ODOO_SESSION_REDIS_SENTINEL_MASTER_NAME")
|
||||||
'ODOO_SESSION_REDIS_SENTINEL_MASTER_NAME'
|
|
||||||
)
|
|
||||||
if sentinel_host and not sentinel_master_name:
|
if sentinel_host and not sentinel_master_name:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
"ODOO_SESSION_REDIS_SENTINEL_MASTER_NAME must be defined "
|
"ODOO_SESSION_REDIS_SENTINEL_MASTER_NAME must be defined "
|
||||||
"when using session_redis"
|
"when using session_redis"
|
||||||
)
|
)
|
||||||
sentinel_port = int(os.environ.get('ODOO_SESSION_REDIS_SENTINEL_PORT', 26379))
|
sentinel_port = int(os.environ.get("ODOO_SESSION_REDIS_SENTINEL_PORT", 26379))
|
||||||
host = os.environ.get('ODOO_SESSION_REDIS_HOST', 'localhost')
|
host = os.environ.get("ODOO_SESSION_REDIS_URL", "localhost")
|
||||||
port = int(os.environ.get('ODOO_SESSION_REDIS_PORT', 6379))
|
port = int(os.environ.get("ODOO_SESSION_REDIS_PORT", 6379))
|
||||||
prefix = os.environ.get('ODOO_SESSION_REDIS_PREFIX')
|
prefix = os.environ.get("ODOO_SESSION_REDIS_PREFIX")
|
||||||
url = os.environ.get('ODOO_SESSION_REDIS_URL')
|
url = os.environ.get("ODOO_SESSION_REDIS_URL")
|
||||||
password = os.environ.get('ODOO_SESSION_REDIS_PASSWORD')
|
password = os.environ.get("ODOO_SESSION_REDIS_PASSWORD")
|
||||||
expiration = os.environ.get('ODOO_SESSION_REDIS_EXPIRATION')
|
expiration = os.environ.get("ODOO_SESSION_REDIS_EXPIRATION")
|
||||||
anon_expiration = os.environ.get('ODOO_SESSION_REDIS_EXPIRATION_ANONYMOUS')
|
anon_expiration = os.environ.get("ODOO_SESSION_REDIS_EXPIRATION_ANONYMOUS")
|
||||||
|
|
||||||
|
|
||||||
def session_store():
|
def session_store():
|
||||||
if sentinel_host:
|
if sentinel_host:
|
||||||
sentinel = Sentinel([(sentinel_host, sentinel_port)],
|
sentinel = Sentinel([(sentinel_host, sentinel_port)], password=password)
|
||||||
password=password)
|
|
||||||
redis_client = sentinel.master_for(sentinel_master_name)
|
redis_client = sentinel.master_for(sentinel_master_name)
|
||||||
elif url:
|
elif url:
|
||||||
redis_client = redis.from_url(url)
|
redis_client = redis.from_url(url)
|
||||||
else:
|
else:
|
||||||
redis_client = redis.Redis(host=host, port=port, password=password)
|
redis_client = redis.Redis(host=host, port=port, password=password)
|
||||||
return RedisSessionStore(redis=redis_client, prefix=prefix,
|
return RedisSessionStore(
|
||||||
expiration=expiration,
|
redis=redis_client,
|
||||||
anon_expiration=anon_expiration,
|
prefix=prefix,
|
||||||
session_class=Session)
|
expiration=expiration,
|
||||||
|
anon_expiration=anon_expiration,
|
||||||
|
session_class=Session,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def session_gc(session_store):
|
def session_gc(session_store):
|
||||||
""" Do not garbage collect the sessions
|
"""Do not garbage collect the sessions
|
||||||
|
|
||||||
Redis keys are automatically cleaned at the end of their
|
Redis keys are automatically cleaned at the end of their
|
||||||
expiration.
|
expiration.
|
||||||
@@ -79,18 +79,26 @@ def purge_fs_sessions(path):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
if is_true(os.environ.get('ODOO_SESSION_REDIS')):
|
if is_true(os.environ.get("ODOO_SESSION_REDIS")):
|
||||||
if sentinel_host:
|
if sentinel_host:
|
||||||
_logger.debug("HTTP sessions stored in Redis with prefix '%s'. "
|
_logger.debug(
|
||||||
"Using Sentinel on %s:%s",
|
"HTTP sessions stored in Redis with prefix '%s'. "
|
||||||
sentinel_host, sentinel_port, prefix or '')
|
"Using Sentinel on %s:%s",
|
||||||
|
sentinel_host,
|
||||||
|
sentinel_port,
|
||||||
|
prefix or "",
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
_logger.debug("HTTP sessions stored in Redis with prefix '%s' on "
|
_logger.debug(
|
||||||
"%s:%s", host, port, prefix or '')
|
"HTTP sessions stored in Redis with prefix '%s' on " "%s:%s",
|
||||||
|
host,
|
||||||
|
port,
|
||||||
|
prefix or "",
|
||||||
|
)
|
||||||
|
|
||||||
store = session_store()
|
store = session_store()
|
||||||
for handler in openerp.service.wsgi_server.module_handlers:
|
for handler in openerp.service.wsgi_server.module_handlers:
|
||||||
if hasattr(handler, 'session_store'):
|
if hasattr(handler, "session_store"):
|
||||||
handler.session_store = store
|
handler.session_store = store
|
||||||
http.session_gc = session_gc
|
http.session_gc = session_gc
|
||||||
# clean the existing sessions on the file system
|
# clean the existing sessions on the file system
|
||||||
|
|||||||
Reference in New Issue
Block a user