Skip to content

Commit

Permalink
just an intermediate state
Browse files Browse the repository at this point in the history
  • Loading branch information
r-peschke committed Sep 30, 2024
1 parent 5a26954 commit 78e2faf
Show file tree
Hide file tree
Showing 12 changed files with 473 additions and 142 deletions.
4 changes: 2 additions & 2 deletions openslides_backend/action/action_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import fastjsonschema

from openslides_backend.database.db_connection_handling import get_current_os_conn
from openslides_backend.database.db_connection_handling import get_new_os_conn

from ..shared.exceptions import (
ActionException,
Expand Down Expand Up @@ -105,7 +105,7 @@ def handle_request(
parsing all actions. In the end it sends everything to the event store.
"""
with make_span(self.env, "handle request"):
with get_current_os_conn() as db_connection:
with get_new_os_conn() as db_connection:
self.db_connection = db_connection
self.user_id = user_id
self.internal = internal
Expand Down
7 changes: 5 additions & 2 deletions openslides_backend/database/db_connection_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

import psycopg
import psycopg_pool

from openslides_backend.shared.env import Environment
from openslides_backend.shared.exceptions import DatabaseException

env = Environment(os.environ)
conn_string_without_db = f"host='{env.DATABASE_HOST}' port='{env.DATABASE_PORT}' user='{env.DATABASE_USER}' password='{env.PGPASSWORD}' "

def configure_connection(conn: psycopg.Connection) -> None:
""" callback, will be called after creation of new connection from connection pool"""
conn.isolation_level = psycopg.IsolationLevel.SERIALIZABLE

def create_os_conn_pool(open: bool = True) -> psycopg_pool.ConnectionPool:
"""create the global connection pool on the openslides-db"""
Expand All @@ -32,6 +34,7 @@ def create_os_conn_pool(open: bool = True) -> psycopg_pool.ConnectionPool:
max_idle=float(env.DB_POOL_MAX_IDLE),
reconnect_timeout=float(env.DB_POOL_RECONNECT_TIMEOUT),
num_workers=int(env.DB_POOL_NUM_WORKERS),
configure= configure_connection,
)
return os_conn_pool

Expand All @@ -50,7 +53,7 @@ def get_current_os_conn_pool() -> psycopg_pool.ConnectionPool:
return os_conn_pool


def get_current_os_conn() -> contextlib._GeneratorContextManager[psycopg.Connection]:
def get_new_os_conn() -> contextlib._GeneratorContextManager[psycopg.Connection]:
os_conn_pool = get_current_os_conn_pool()
return os_conn_pool.connection()

Expand Down
Loading

0 comments on commit 78e2faf

Please sign in to comment.