refactor is_representation_paused to check into the database

This commit is contained in:
Félix David 2023-01-13 14:55:11 +01:00
parent 1bf9be8c0d
commit 30e8bc5bb8
3 changed files with 38 additions and 21 deletions

View file

@ -328,9 +328,12 @@ class GDriveHandler(AbstractProvider):
last_tick = status = response = None
status_val = 0
while response is None:
if server.is_representation_paused(representation['_id'],
check_parents=True,
project_name=project_name):
if server.is_representation_paused(
project_name,
representation['_id'],
site,
check_parents=True
):
raise ValueError("Paused during process, please redo.")
if status:
status_val = float(status.progress())
@ -415,9 +418,12 @@ class GDriveHandler(AbstractProvider):
last_tick = status = response = None
status_val = 0
while response is None:
if server.is_representation_paused(representation['_id'],
check_parents=True,
project_name=project_name):
if server.is_representation_paused(
project_name,
representation['_id'],
site,
check_parents=True
):
raise ValueError("Paused during process, please redo.")
if status:
status_val = float(status.progress())

View file

@ -284,9 +284,6 @@ class SyncServerThread(threading.Thread):
# building folder tree structure in memory
# call only if needed, eg. DO_UPLOAD or DO_DOWNLOAD
for sync in sync_repres:
if self.module.\
is_representation_paused(sync['_id']):
continue
if limit <= 0:
continue
files = sync.get("files") or []

View file

@ -500,27 +500,41 @@ class SyncServerModule(OpenPypeModule, ITrayModule):
self.reset_site_on_representation(project_name, representation_id,
site_name=site_name, pause=False)
def is_representation_paused(self, representation_id,
check_parents=False, project_name=None):
def is_representation_paused(self, project_name, representation_id,
site_name, check_parents=False):
"""
Returns if 'representation_id' is paused or not.
Returns if 'representation_id' is paused or not for site.
Args:
representation_id (string): MongoDB objectId value
project_name (str): project to check if paused
representation_id (str): MongoDB objectId value
site (str): site to check representation is paused for
check_parents (bool): check if parent project or server itself
are not paused
project_name (string): project to check if paused
if 'check_parents', 'project_name' should be set too
Returns:
(bool)
"""
condition = representation_id in self._paused_representations
if check_parents and project_name:
condition = condition or \
self.is_project_paused(project_name) or \
self.is_paused()
return condition
representation = get_representation_by_id(project_name,
representation_id,
fields=["files.sites"])
if not representation:
return False
# Check parents are paused
if check_parents and (self.is_project_paused(project_name) or \
self.is_paused()):
return True
# Check if representation is paused
for file_info in representation.get("files", []):
for site in file_info.get("sites", []):
if site["name"] != site_name:
continue
return site.get("paused", False)
return False
def pause_project(self, project_name):
"""