mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
modified mongo validation in ftrack
This commit is contained in:
parent
355872938b
commit
017a2df395
1 changed files with 11 additions and 10 deletions
|
|
@ -14,7 +14,10 @@ import uuid
|
||||||
|
|
||||||
import ftrack_api
|
import ftrack_api
|
||||||
import pymongo
|
import pymongo
|
||||||
from pype.lib import get_pype_execute_args
|
from pype.lib import (
|
||||||
|
get_pype_execute_args,
|
||||||
|
PypeMongoConnection
|
||||||
|
)
|
||||||
from pype.modules.ftrack.lib import (
|
from pype.modules.ftrack.lib import (
|
||||||
credentials,
|
credentials,
|
||||||
get_ftrack_url_from_settings
|
get_ftrack_url_from_settings
|
||||||
|
|
@ -35,17 +38,18 @@ class MongoPermissionsError(Exception):
|
||||||
super().__init__(message)
|
super().__init__(message)
|
||||||
|
|
||||||
|
|
||||||
def check_mongo_url(host, port, log_error=False):
|
def check_mongo_url(mongo_uri, log_error=False):
|
||||||
"""Checks if mongo server is responding"""
|
"""Checks if mongo server is responding"""
|
||||||
try:
|
try:
|
||||||
client = pymongo.MongoClient(host=host, port=port)
|
client = pymongo.MongoClient(mongo_uri)
|
||||||
# Force connection on a request as the connect=True parameter of
|
# Force connection on a request as the connect=True parameter of
|
||||||
# MongoClient seems to be useless here
|
# MongoClient seems to be useless here
|
||||||
client.server_info()
|
client.server_info()
|
||||||
|
client.close()
|
||||||
except pymongo.errors.ServerSelectionTimeoutError as err:
|
except pymongo.errors.ServerSelectionTimeoutError as err:
|
||||||
if log_error:
|
if log_error:
|
||||||
print("Can't connect to MongoDB at {}:{} because: {}".format(
|
print("Can't connect to MongoDB at {} because: {}".format(
|
||||||
host, port, err
|
mongo_uri, err
|
||||||
))
|
))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
@ -175,11 +179,8 @@ def main_loop(ftrack_url):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
os.environ["FTRACK_EVENT_SUB_ID"] = str(uuid.uuid1())
|
os.environ["FTRACK_EVENT_SUB_ID"] = str(uuid.uuid1())
|
||||||
# Get mongo hostname and port for testing mongo connection
|
|
||||||
|
|
||||||
mongo_uri, mongo_port, database_name, collection_name = (
|
mongo_uri = PypeMongoConnection.get_default_mongo_url()
|
||||||
get_ftrack_event_mongo_info()
|
|
||||||
)
|
|
||||||
|
|
||||||
# Current file
|
# Current file
|
||||||
file_path = os.path.dirname(os.path.realpath(__file__))
|
file_path = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
@ -257,7 +258,7 @@ def main_loop(ftrack_url):
|
||||||
ftrack_accessible = check_ftrack_url(ftrack_url)
|
ftrack_accessible = check_ftrack_url(ftrack_url)
|
||||||
|
|
||||||
if not mongo_accessible:
|
if not mongo_accessible:
|
||||||
mongo_accessible = check_mongo_url(mongo_uri, mongo_port)
|
mongo_accessible = check_mongo_url(mongo_uri)
|
||||||
|
|
||||||
# Run threads only if Ftrack is accessible
|
# Run threads only if Ftrack is accessible
|
||||||
if not ftrack_accessible or not mongo_accessible:
|
if not ftrack_accessible or not mongo_accessible:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue