Changes:
- fixed connexion pool exhausted using Semaphores - fixed session-replay-url signing
This commit is contained in:
parent
491ac20502
commit
dcfab07609
2 changed files with 20 additions and 11 deletions
|
|
@ -1,10 +1,10 @@
|
|||
from chalicelib.utils.helper import environ
|
||||
|
||||
import boto3
|
||||
from chalicelib.utils.s3 import client
|
||||
|
||||
|
||||
def get_web(sessionId):
|
||||
return boto3.client('s3', region_name=environ["sessions_region"]).generate_presigned_url(
|
||||
return client.generate_presigned_url(
|
||||
'get_object',
|
||||
Params={
|
||||
'Bucket': environ["sessions_bucket"],
|
||||
|
|
@ -15,7 +15,7 @@ def get_web(sessionId):
|
|||
|
||||
|
||||
def get_ios(sessionId):
|
||||
return boto3.client('s3', region_name=environ["ios_region"]).generate_presigned_url(
|
||||
return client.generate_presigned_url(
|
||||
'get_object',
|
||||
Params={
|
||||
'Bucket': environ["ios_bucket"],
|
||||
|
|
|
|||
|
|
@ -9,9 +9,25 @@ PG_CONFIG = {"host": environ["pg_host"],
|
|||
"port": int(environ["pg_port"])}
|
||||
|
||||
from psycopg2 import pool
|
||||
from threading import Semaphore
|
||||
|
||||
|
||||
class ORThreadedConnectionPool(psycopg2.pool.ThreadedConnectionPool):
|
||||
def __init__(self, minconn, maxconn, *args, **kwargs):
|
||||
self._semaphore = Semaphore(maxconn)
|
||||
super().__init__(minconn, maxconn, *args, **kwargs)
|
||||
|
||||
def getconn(self, *args, **kwargs):
|
||||
self._semaphore.acquire()
|
||||
return super().getconn(*args, **kwargs)
|
||||
|
||||
def putconn(self, *args, **kwargs):
|
||||
super().putconn(*args, **kwargs)
|
||||
self._semaphore.release()
|
||||
|
||||
|
||||
try:
|
||||
postgreSQL_pool = psycopg2.pool.ThreadedConnectionPool(6, 20, **PG_CONFIG)
|
||||
postgreSQL_pool = ORThreadedConnectionPool(20, 100, **PG_CONFIG)
|
||||
if (postgreSQL_pool):
|
||||
print("Connection pool created successfully")
|
||||
except (Exception, psycopg2.DatabaseError) as error:
|
||||
|
|
@ -19,13 +35,6 @@ except (Exception, psycopg2.DatabaseError) as error:
|
|||
raise error
|
||||
|
||||
|
||||
# finally:
|
||||
# # closing database connection.
|
||||
# # use closeall method to close all the active connection if you want to turn of the application
|
||||
# if (postgreSQL_pool):
|
||||
# postgreSQL_pool.closeall
|
||||
# print("PostgreSQL connection pool is closed")
|
||||
|
||||
class PostgresClient:
|
||||
connection = None
|
||||
cursor = None
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue