add priority to add_site

This commit is contained in:
Félix David 2022-11-08 18:57:02 +01:00
parent a76ad60351
commit 3ad8e95ca4
3 changed files with 16 additions and 18 deletions

View file

@ -1,4 +1,5 @@
from aiohttp.web_response import Response
from openpype.client.entities import get_representation_by_id
from openpype.lib import Logger
@ -29,11 +30,6 @@ class SyncServerModuleRestApi:
self.prefix + "/add_sites_to_representations",
self.add_sites_to_representations,
)
self.server_manager.add_route(
"GET",
self.prefix + "/files_are_processed",
self.files_are_processed,
)
async def add_sites_to_representations(self, request):
# Extract data from request
@ -54,15 +50,14 @@ class SyncServerModuleRestApi:
for representation_id in representations:
for site in sites:
self.module.add_site(
project_name, representation_id, site, force=True
project_name,
representation_id,
site,
force=True,
priority=99,
)
# Force timer to run immediately
self.module.reset_timer()
return Response(status=200)
async def files_are_processed(self, _request):
return Response(
body=bytes(self.module.sync_server_thread.files_are_processed)
)

View file

@ -243,7 +243,6 @@ class SyncServerThread(threading.Thread):
self.is_running = False
self.executor = concurrent.futures.ThreadPoolExecutor(max_workers=3)
self.timer = None
self.files_are_processed = False
def run(self):
self.is_running = True
@ -398,8 +397,6 @@ class SyncServerThread(threading.Thread):
representation,
site,
error)
# Trigger files process finished
self.files_are_processed = False
duration = time.time() - start_time
self.log.debug("One loop took {:.2f}s".format(duration))
@ -466,7 +463,6 @@ class SyncServerThread(threading.Thread):
if self.timer:
self.timer.cancel()
self.timer = None
self.files_are_processed = True
def _working_sites(self, project_name):
if self.module.is_project_paused(project_name):

View file

@ -136,7 +136,7 @@ class SyncServerModule(OpenPypeModule, ITrayModule):
""" Start of Public API """
def add_site(self, project_name, representation_id, site_name=None,
force=False):
force=False, priority=None):
"""
Adds new site to representation to be synced.
@ -152,6 +152,7 @@ class SyncServerModule(OpenPypeModule, ITrayModule):
representation_id (string): MongoDB _id value
site_name (string): name of configured and active site
force (bool): reset site if exists
priority (int): set priority
Throws:
SiteAlreadyPresentError - if adding already existing site and
@ -167,7 +168,8 @@ class SyncServerModule(OpenPypeModule, ITrayModule):
self.reset_site_on_representation(project_name,
representation_id,
site_name=site_name,
force=force)
force=force,
priority=priority)
def remove_site(self, project_name, representation_id, site_name,
remove_local_files=False):
@ -1655,7 +1657,7 @@ class SyncServerModule(OpenPypeModule, ITrayModule):
def reset_site_on_representation(self, project_name, representation_id,
side=None, file_id=None, site_name=None,
remove=False, pause=None, force=False):
remove=False, pause=None, force=False, priority=None):
"""
Reset information about synchronization for particular 'file_id'
and provider.
@ -1678,6 +1680,7 @@ class SyncServerModule(OpenPypeModule, ITrayModule):
remove (bool): if True remove site altogether
pause (bool or None): if True - pause, False - unpause
force (bool): hard reset - currently only for add_site
priority (int): set priority
Raises:
SiteAlreadyPresentError - if adding already existing site and
@ -1705,6 +1708,10 @@ class SyncServerModule(OpenPypeModule, ITrayModule):
elem = {"name": site_name}
# Add priority
if priority:
elem["priority"] = priority
if file_id: # reset site for particular file
self._reset_site_for_file(project_name, representation_id,
elem, file_id, site_name)