mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
Merge pull request #331 from pypeclub/bugfix/mongo_url_components
Bugfix/mongo url components
This commit is contained in:
commit
d2efdf0dcf
3 changed files with 9 additions and 30 deletions
|
|
@ -26,7 +26,7 @@ from pype.api import (
|
|||
compose_url
|
||||
)
|
||||
|
||||
from pype.modules.ftrack.lib.custom_db_connector import DbConnector
|
||||
from pype.modules.ftrack.lib.custom_db_connector import CustomDbConnector
|
||||
|
||||
|
||||
TOPIC_STATUS_SERVER = "pype.event.server.status"
|
||||
|
|
@ -44,15 +44,8 @@ def get_ftrack_event_mongo_info():
|
|||
mongo_url = os.environ.get("FTRACK_EVENTS_MONGO_URL")
|
||||
if mongo_url is not None:
|
||||
components = decompose_url(mongo_url)
|
||||
_used_ftrack_url = True
|
||||
else:
|
||||
components = get_default_components()
|
||||
_used_ftrack_url = False
|
||||
|
||||
if not _used_ftrack_url or components["database"] is None:
|
||||
components["database"] = database_name
|
||||
|
||||
components.pop("collection", None)
|
||||
|
||||
uri = compose_url(**components)
|
||||
|
||||
|
|
@ -166,10 +159,10 @@ class ProcessEventHub(SocketBaseEventHub):
|
|||
pypelog = Logger().get_logger("Session Processor")
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.dbcon = DbConnector(
|
||||
self.dbcon = CustomDbConnector(
|
||||
self.uri,
|
||||
self.port,
|
||||
self.database,
|
||||
self.port,
|
||||
self.table_name
|
||||
)
|
||||
super(ProcessEventHub, self).__init__(*args, **kwargs)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ from pype.modules.ftrack.ftrack_server.lib import (
|
|||
get_ftrack_event_mongo_info,
|
||||
TOPIC_STATUS_SERVER, TOPIC_STATUS_SERVER_RESULT
|
||||
)
|
||||
from pype.modules.ftrack.lib.custom_db_connector import DbConnector
|
||||
from pype.modules.ftrack.lib.custom_db_connector import CustomDbConnector
|
||||
from pype.api import Logger
|
||||
|
||||
log = Logger().get_logger("Event storer")
|
||||
|
|
@ -24,7 +24,7 @@ class SessionFactory:
|
|||
|
||||
|
||||
uri, port, database, table_name = get_ftrack_event_mongo_info()
|
||||
dbcon = DbConnector(uri, port, database, table_name)
|
||||
dbcon = CustomDbConnector(uri, database, port, table_name)
|
||||
|
||||
# ignore_topics = ["ftrack.meta.connected"]
|
||||
ignore_topics = []
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ def auto_reconnect(func):
|
|||
|
||||
|
||||
def check_active_table(func):
|
||||
"""Check if DbConnector has active table before db method is called"""
|
||||
"""Check if CustomDbConnector has active collection."""
|
||||
@functools.wraps(func)
|
||||
def decorated(obj, *args, **kwargs):
|
||||
if not obj.active_table:
|
||||
|
|
@ -50,23 +50,12 @@ def check_active_table(func):
|
|||
return decorated
|
||||
|
||||
|
||||
def check_active_table(func):
|
||||
"""Handling auto reconnect in 3 retry times"""
|
||||
@functools.wraps(func)
|
||||
def decorated(obj, *args, **kwargs):
|
||||
if not obj.active_table:
|
||||
raise NotActiveTable("Active table is not set. (This is bug)")
|
||||
return func(obj, *args, **kwargs)
|
||||
|
||||
return decorated
|
||||
|
||||
|
||||
class DbConnector:
|
||||
class CustomDbConnector:
|
||||
log = logging.getLogger(__name__)
|
||||
timeout = int(os.environ["AVALON_TIMEOUT"])
|
||||
|
||||
def __init__(
|
||||
self, uri, port=None, database_name=None, table_name=None
|
||||
self, uri, database_name, port=None, table_name=None
|
||||
):
|
||||
self._mongo_client = None
|
||||
self._sentry_client = None
|
||||
|
|
@ -79,9 +68,6 @@ class DbConnector:
|
|||
if port is None:
|
||||
port = components.get("port")
|
||||
|
||||
if database_name is None:
|
||||
database_name = components.get("database")
|
||||
|
||||
if database_name is None:
|
||||
raise ValueError(
|
||||
"Database is not defined for connection. {}".format(uri)
|
||||
|
|
@ -100,7 +86,7 @@ class DbConnector:
|
|||
# not all methods of PyMongo database are implemented with this it is
|
||||
# possible to use them too
|
||||
try:
|
||||
return super(DbConnector, self).__getattribute__(attr)
|
||||
return super(CustomDbConnector, self).__getattribute__(attr)
|
||||
except AttributeError:
|
||||
if self.active_table is None:
|
||||
raise NotActiveTable()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue