feat(api): limited long task DB
This commit is contained in:
parent
4d1a13d8f5
commit
3cb45b7a90
2 changed files with 11 additions and 6 deletions
|
|
@ -1201,7 +1201,7 @@ def get_session_ids_by_user_ids(project_id, user_ids):
|
|||
|
||||
|
||||
def delete_sessions_by_session_ids(session_ids):
|
||||
with pg_client.PostgresClient(long_query=True) as cur:
|
||||
with pg_client.PostgresClient(unlimited_query=True) as cur:
|
||||
query = cur.mogrify(
|
||||
"""\
|
||||
DELETE FROM public.sessions
|
||||
|
|
@ -1215,7 +1215,7 @@ def delete_sessions_by_session_ids(session_ids):
|
|||
|
||||
|
||||
def delete_sessions_by_user_ids(project_id, user_ids):
|
||||
with pg_client.PostgresClient(long_query=True) as cur:
|
||||
with pg_client.PostgresClient(unlimited_query=True) as cur:
|
||||
query = cur.mogrify(
|
||||
"""\
|
||||
DELETE FROM public.sessions
|
||||
|
|
@ -1229,6 +1229,6 @@ def delete_sessions_by_user_ids(project_id, user_ids):
|
|||
|
||||
|
||||
def count_all():
|
||||
with pg_client.PostgresClient(long_query=True) as cur:
|
||||
with pg_client.PostgresClient(unlimited_query=True) as cur:
|
||||
row = cur.execute(query="SELECT COUNT(session_id) AS count FROM public.sessions")
|
||||
return row.get("count", 0)
|
||||
|
|
|
|||
|
|
@ -74,12 +74,17 @@ class PostgresClient:
|
|||
cursor = None
|
||||
long_query = False
|
||||
|
||||
def __init__(self, long_query=False):
|
||||
def __init__(self, long_query=False, unlimited_query=False):
|
||||
self.long_query = long_query
|
||||
if long_query:
|
||||
if unlimited_query:
|
||||
long_config = dict(_PG_CONFIG)
|
||||
long_config["application_name"] += "-UNLIMITED"
|
||||
self.connection = psycopg2.connect(**long_config)
|
||||
elif long_query:
|
||||
long_config = dict(_PG_CONFIG)
|
||||
long_config["application_name"] += "-LONG"
|
||||
self.connection = psycopg2.connect(**_PG_CONFIG)
|
||||
long_config["options"] = f"-c statement_timeout={config('pg_long_timeout', cast=int, default=5*60) * 1000}"
|
||||
self.connection = psycopg2.connect(**long_config)
|
||||
else:
|
||||
self.connection = postgreSQL_pool.getconn()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue