Skip to content

Commit

Permalink
Merge branch 'develop' into enhancement/remove-intent-from-default-se…
Browse files Browse the repository at this point in the history
…ttings
  • Loading branch information
iLLiCiTiT authored Sep 9, 2024
2 parents 9dc6645 + 053b7dc commit 6cf85c6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 27 deletions.
27 changes: 10 additions & 17 deletions client/ayon_ftrack/common/ftrack_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ def __init__(self, handler_paths=None):

self.log = logging.getLogger(__name__)

self.stopped = True
self.is_running = False
self._stopped = True
self._is_running = False

self.handler_paths = handler_paths or []

def stop_session(self):
self.stopped = True
self._stopped = True
if self.session.event_hub.connected is True:
self.session.event_hub.disconnect()
self.session.close()
Expand Down Expand Up @@ -92,18 +92,9 @@ def set_files(self, paths):
exc_info=True
)

def set_handler_paths(self, paths):
self.handler_paths = paths
if self.is_running:
self.stop_session()
self.run_server()

elif not self.stopped:
self.run_server()

def run_server(self, session=None, load_files=True):
self.stopped = False
self.is_running = True
self._stopped = False
self._is_running = True
if not session:
session = ftrack_api.Session(auto_connect_event_hub=True)

Expand Down Expand Up @@ -131,7 +122,7 @@ def run_server(self, session=None, load_files=True):
"Paths to event handlers are not set."
" Ftrack server won't launch."
))
self.is_running = False
self._is_running = False
return

self.set_files(self.handler_paths)
Expand All @@ -141,5 +132,7 @@ def run_server(self, session=None, load_files=True):
self.log.info(msg)

# keep event_hub on session running
self.session.event_hub.wait()
self.is_running = False
try:
self.session.event_hub.wait()
finally:
self._is_running = False
2 changes: 1 addition & 1 deletion services/processor/processor/download_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def downloaded_event_handlers(custom_handlers):
yield event_handler_dirs
finally:
shutil.rmtree(dirpath)
print("downloaded_event_handlers end")
print("Cleaned up downloaded event handlers")


def cleanup_download_root():
Expand Down
3 changes: 3 additions & 0 deletions services/processor/processor/ftrack_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ def wait(self, duration=None):

started = time.time()
while True:
if not self.connected:
self.reconnect()

job = None
empty_queue = False
try:
Expand Down
31 changes: 22 additions & 9 deletions services/processor/processor/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,19 @@ def get_service_label():
])


def _cleanup_session():
session = _GlobalContext.session
_GlobalContext.session = None
if session is not None:
logging.info("Closing ftrack session.")
if session.event_hub.connected is True:
session.event_hub.disconnect()
session.close()


def _create_session():
_cleanup_session()

ftrack_settings = ayon_api.get_service_addon_settings()
ftrack_url = ftrack_settings["ftrack_server"]
service_settings = ftrack_settings["service_settings"]
Expand Down Expand Up @@ -138,10 +150,13 @@ def main_loop():
while not _GlobalContext.stop_event.is_set():
session = create_session()
if session is None:
logging.info(
"Failed to create ftrack session. Will try in 10 seconds."
)
time.sleep(10)
continue

_GlobalContext.session_fail_logged = False
_GlobalContext.session_fail_logged = 0

# Cleanup download root
cleanup_download_root()
Expand All @@ -156,8 +171,11 @@ def main_loop():
handler_paths.extend(custom_handler_dirs)
logging.info("Starting listen server")
server = FtrackServer(handler_paths)
server.run_server(session)
logging.info("Server stopped.")
try:
server.run_server(session)
finally:
logging.info("Server stopped.")
_cleanup_session()
logging.info("Main loop stopped.")


Expand All @@ -172,12 +190,7 @@ def _cleanup_process():
logging.info("Stopping main loop.")
if not _GlobalContext.stop_event.is_set():
_GlobalContext.stop_event.set()
session = _GlobalContext.session
logging.info("Closing ftrack session.")
if session is not None:
if session.event_hub.connected is True:
session.event_hub.disconnect()
session.close()
_cleanup_session()


def main():
Expand Down

0 comments on commit 6cf85c6

Please sign in to comment.