mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 12:54:40 +01:00
Merge branch 'develop' into bugfix/1586-yn-0299-launcher-my-tasks-view-doesnt-refresh-on-new-assignments
This commit is contained in:
commit
721c1fdd8d
5 changed files with 235 additions and 41 deletions
|
|
@ -192,7 +192,9 @@ class HelpContent:
|
|||
self.detail = detail
|
||||
|
||||
|
||||
def load_help_content_from_filepath(filepath):
|
||||
def load_help_content_from_filepath(
|
||||
filepath: str
|
||||
) -> dict[str, dict[str, HelpContent]]:
|
||||
"""Load help content from xml file.
|
||||
Xml file may contain errors and warnings.
|
||||
"""
|
||||
|
|
@ -227,15 +229,20 @@ def load_help_content_from_filepath(filepath):
|
|||
return output
|
||||
|
||||
|
||||
def load_help_content_from_plugin(plugin):
|
||||
def load_help_content_from_plugin(
|
||||
plugin: pyblish.api.Plugin,
|
||||
help_filename: Optional[str] = None,
|
||||
) -> dict[str, dict[str, HelpContent]]:
|
||||
cls = plugin
|
||||
if not inspect.isclass(plugin):
|
||||
cls = plugin.__class__
|
||||
|
||||
plugin_filepath = inspect.getfile(cls)
|
||||
plugin_dir = os.path.dirname(plugin_filepath)
|
||||
basename = os.path.splitext(os.path.basename(plugin_filepath))[0]
|
||||
filename = basename + ".xml"
|
||||
filepath = os.path.join(plugin_dir, "help", filename)
|
||||
if help_filename is None:
|
||||
basename = os.path.splitext(os.path.basename(plugin_filepath))[0]
|
||||
help_filename = basename + ".xml"
|
||||
filepath = os.path.join(plugin_dir, "help", help_filename)
|
||||
return load_help_content_from_filepath(filepath)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import inspect
|
||||
from abc import ABCMeta
|
||||
import typing
|
||||
from typing import Optional
|
||||
from typing import Optional, Any
|
||||
|
||||
import pyblish.api
|
||||
import pyblish.logic
|
||||
|
|
@ -82,22 +82,51 @@ class PublishValidationError(PublishError):
|
|||
|
||||
|
||||
class PublishXmlValidationError(PublishValidationError):
|
||||
"""Raise an error from a dedicated xml file.
|
||||
|
||||
Can be useful to have one xml file with different possible messages that
|
||||
helps to avoid flood code with dedicated artist messages.
|
||||
|
||||
XML files should live relative to the plugin file location:
|
||||
'{plugin dir}/help/some_plugin.xml'.
|
||||
|
||||
Args:
|
||||
plugin (pyblish.api.Plugin): Plugin that raised an error. Is used
|
||||
to get path to xml file.
|
||||
message (str): Exception message, can be technical, is used for
|
||||
console output.
|
||||
key (Optional[str]): XML file can contain multiple error messages, key
|
||||
is used to get one of them. By default is used 'main'.
|
||||
formatting_data (Optional[dict[str, Any]): Error message can have
|
||||
variables to fill.
|
||||
help_filename (Optional[str]): Name of xml file with messages. By
|
||||
default, is used filename where plugin lives with .xml extension.
|
||||
|
||||
"""
|
||||
def __init__(
|
||||
self, plugin, message, key=None, formatting_data=None
|
||||
):
|
||||
self,
|
||||
plugin: pyblish.api.Plugin,
|
||||
message: str,
|
||||
key: Optional[str] = None,
|
||||
formatting_data: Optional[dict[str, Any]] = None,
|
||||
help_filename: Optional[str] = None,
|
||||
) -> None:
|
||||
if key is None:
|
||||
key = "main"
|
||||
|
||||
if not formatting_data:
|
||||
formatting_data = {}
|
||||
result = load_help_content_from_plugin(plugin)
|
||||
result = load_help_content_from_plugin(plugin, help_filename)
|
||||
content_obj = result["errors"][key]
|
||||
description = content_obj.description.format(**formatting_data)
|
||||
detail = content_obj.detail
|
||||
if detail:
|
||||
detail = detail.format(**formatting_data)
|
||||
super(PublishXmlValidationError, self).__init__(
|
||||
message, content_obj.title, description, detail
|
||||
super().__init__(
|
||||
message,
|
||||
content_obj.title,
|
||||
description,
|
||||
detail
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
21
client/ayon_core/plugins/publish/help/upload_file.xml
Normal file
21
client/ayon_core/plugins/publish/help/upload_file.xml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<root>
|
||||
<error id="main">
|
||||
<title>{upload_type} upload timed out</title>
|
||||
<description>
|
||||
## {upload_type} upload failed after retries
|
||||
|
||||
The connection to the AYON server timed out while uploading a file.
|
||||
|
||||
### How to resolve?
|
||||
|
||||
1. Try publishing again. Intermittent network hiccups often resolve on retry.
|
||||
2. Ensure your network/VPN is stable and large uploads are allowed.
|
||||
3. If it keeps failing, try again later or contact your admin.
|
||||
|
||||
<pre>File: {file}
|
||||
Error: {error}</pre>
|
||||
|
||||
</description>
|
||||
</error>
|
||||
</root>
|
||||
|
|
@ -1,11 +1,17 @@
|
|||
import os
|
||||
import time
|
||||
|
||||
import pyblish.api
|
||||
import ayon_api
|
||||
from ayon_api import TransferProgress
|
||||
from ayon_api.server_api import RequestTypes
|
||||
import pyblish.api
|
||||
|
||||
from ayon_core.lib import get_media_mime_type
|
||||
from ayon_core.pipeline.publish import get_publish_repre_path
|
||||
from ayon_core.lib import get_media_mime_type, format_file_size
|
||||
from ayon_core.pipeline.publish import (
|
||||
PublishXmlValidationError,
|
||||
get_publish_repre_path,
|
||||
)
|
||||
import requests.exceptions
|
||||
|
||||
|
||||
class IntegrateAYONReview(pyblish.api.InstancePlugin):
|
||||
|
|
@ -44,7 +50,7 @@ class IntegrateAYONReview(pyblish.api.InstancePlugin):
|
|||
if "webreview" not in repre_tags:
|
||||
continue
|
||||
|
||||
# exclude representations with are going to be published on farm
|
||||
# exclude representations going to be published on farm
|
||||
if "publish_on_farm" in repre_tags:
|
||||
continue
|
||||
|
||||
|
|
@ -75,18 +81,13 @@ class IntegrateAYONReview(pyblish.api.InstancePlugin):
|
|||
f"/projects/{project_name}"
|
||||
f"/versions/{version_id}/reviewables{query}"
|
||||
)
|
||||
filename = os.path.basename(repre_path)
|
||||
# Upload the reviewable
|
||||
self.log.info(f"Uploading reviewable '{label or filename}' ...")
|
||||
|
||||
headers = ayon_con.get_headers(content_type)
|
||||
headers["x-file-name"] = filename
|
||||
self.log.info(f"Uploading reviewable {repre_path}")
|
||||
ayon_con.upload_file(
|
||||
# Upload with retries and clear help if it keeps failing
|
||||
self._upload_with_retries(
|
||||
ayon_con,
|
||||
endpoint,
|
||||
repre_path,
|
||||
headers=headers,
|
||||
request_type=RequestTypes.post,
|
||||
content_type,
|
||||
)
|
||||
|
||||
def _get_review_label(self, repre, uploaded_labels):
|
||||
|
|
@ -100,3 +101,74 @@ class IntegrateAYONReview(pyblish.api.InstancePlugin):
|
|||
idx += 1
|
||||
label = f"{orig_label}_{idx}"
|
||||
return label
|
||||
|
||||
def _upload_with_retries(
|
||||
self,
|
||||
ayon_con: ayon_api.ServerAPI,
|
||||
endpoint: str,
|
||||
repre_path: str,
|
||||
content_type: str,
|
||||
):
|
||||
"""Upload file with simple retries."""
|
||||
filename = os.path.basename(repre_path)
|
||||
|
||||
headers = ayon_con.get_headers(content_type)
|
||||
headers["x-file-name"] = filename
|
||||
max_retries = ayon_con.get_default_max_retries()
|
||||
# Retries are already implemented in 'ayon_api.upload_file'
|
||||
# - added in ayon api 1.2.7
|
||||
if hasattr(TransferProgress, "get_attempt"):
|
||||
max_retries = 1
|
||||
|
||||
size = os.path.getsize(repre_path)
|
||||
self.log.info(
|
||||
f"Uploading '{repre_path}' (size: {format_file_size(size)})"
|
||||
)
|
||||
|
||||
# How long to sleep before next attempt
|
||||
wait_time = 1
|
||||
last_error = None
|
||||
for attempt in range(max_retries):
|
||||
attempt += 1
|
||||
start = time.time()
|
||||
try:
|
||||
output = ayon_con.upload_file(
|
||||
endpoint,
|
||||
repre_path,
|
||||
headers=headers,
|
||||
request_type=RequestTypes.post,
|
||||
)
|
||||
self.log.debug(f"Uploaded in {time.time() - start}s.")
|
||||
return output
|
||||
|
||||
except (
|
||||
requests.exceptions.Timeout,
|
||||
requests.exceptions.ConnectionError
|
||||
) as exc:
|
||||
# Log and retry with backoff if attempts remain
|
||||
if attempt >= max_retries:
|
||||
last_error = exc
|
||||
break
|
||||
|
||||
self.log.warning(
|
||||
f"Review upload failed ({attempt}/{max_retries})"
|
||||
f" after {time.time() - start}s."
|
||||
f" Retrying in {wait_time}s...",
|
||||
exc_info=True,
|
||||
)
|
||||
time.sleep(wait_time)
|
||||
|
||||
# Exhausted retries - raise a user-friendly validation error with help
|
||||
raise PublishXmlValidationError(
|
||||
self,
|
||||
(
|
||||
"Upload of reviewable timed out or failed after multiple"
|
||||
" attempts. Please try publishing again."
|
||||
),
|
||||
formatting_data={
|
||||
"upload_type": "Review",
|
||||
"file": repre_path,
|
||||
"error": str(last_error),
|
||||
},
|
||||
help_filename="upload_file.xml",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -24,11 +24,16 @@
|
|||
|
||||
import os
|
||||
import collections
|
||||
import time
|
||||
|
||||
import pyblish.api
|
||||
import ayon_api
|
||||
from ayon_api import RequestTypes
|
||||
from ayon_api import RequestTypes, TransferProgress
|
||||
from ayon_api.operations import OperationsSession
|
||||
import pyblish.api
|
||||
import requests
|
||||
|
||||
from ayon_core.lib import get_media_mime_type, format_file_size
|
||||
from ayon_core.pipeline.publish import PublishXmlValidationError
|
||||
|
||||
|
||||
InstanceFilterResult = collections.namedtuple(
|
||||
|
|
@ -164,25 +169,17 @@ class IntegrateThumbnailsAYON(pyblish.api.ContextPlugin):
|
|||
return os.path.normpath(filled_path)
|
||||
|
||||
def _create_thumbnail(self, project_name: str, src_filepath: str) -> str:
|
||||
"""Upload thumbnail to AYON and return its id.
|
||||
|
||||
This is temporary fix of 'create_thumbnail' function in ayon_api to
|
||||
fix jpeg mime type.
|
||||
|
||||
"""
|
||||
mime_type = None
|
||||
with open(src_filepath, "rb") as stream:
|
||||
if b"\xff\xd8\xff" == stream.read(3):
|
||||
mime_type = "image/jpeg"
|
||||
|
||||
"""Upload thumbnail to AYON and return its id."""
|
||||
mime_type = get_media_mime_type(src_filepath)
|
||||
if mime_type is None:
|
||||
return ayon_api.create_thumbnail(project_name, src_filepath)
|
||||
return ayon_api.create_thumbnail(
|
||||
project_name, src_filepath
|
||||
)
|
||||
|
||||
response = ayon_api.upload_file(
|
||||
response = self._upload_with_retries(
|
||||
f"projects/{project_name}/thumbnails",
|
||||
src_filepath,
|
||||
request_type=RequestTypes.post,
|
||||
headers={"Content-Type": mime_type},
|
||||
mime_type,
|
||||
)
|
||||
response.raise_for_status()
|
||||
return response.json()["id"]
|
||||
|
|
@ -248,3 +245,71 @@ class IntegrateThumbnailsAYON(pyblish.api.ContextPlugin):
|
|||
or instance.data.get("name")
|
||||
or "N/A"
|
||||
)
|
||||
|
||||
def _upload_with_retries(
|
||||
self,
|
||||
endpoint: str,
|
||||
repre_path: str,
|
||||
content_type: str,
|
||||
):
|
||||
"""Upload file with simple retries."""
|
||||
ayon_con = ayon_api.get_server_api_connection()
|
||||
headers = ayon_con.get_headers(content_type)
|
||||
max_retries = ayon_con.get_default_max_retries()
|
||||
# Retries are already implemented in 'ayon_api.upload_file'
|
||||
# - added in ayon api 1.2.7
|
||||
if hasattr(TransferProgress, "get_attempt"):
|
||||
max_retries = 1
|
||||
|
||||
size = os.path.getsize(repre_path)
|
||||
self.log.info(
|
||||
f"Uploading '{repre_path}' (size: {format_file_size(size)})"
|
||||
)
|
||||
|
||||
# How long to sleep before next attempt
|
||||
wait_time = 1
|
||||
last_error = None
|
||||
for attempt in range(max_retries):
|
||||
attempt += 1
|
||||
start = time.time()
|
||||
try:
|
||||
output = ayon_con.upload_file(
|
||||
endpoint,
|
||||
repre_path,
|
||||
headers=headers,
|
||||
request_type=RequestTypes.post,
|
||||
)
|
||||
self.log.debug(f"Uploaded in {time.time() - start}s.")
|
||||
return output
|
||||
|
||||
except (
|
||||
requests.exceptions.Timeout,
|
||||
requests.exceptions.ConnectionError
|
||||
) as exc:
|
||||
# Log and retry with backoff if attempts remain
|
||||
if attempt >= max_retries:
|
||||
last_error = exc
|
||||
break
|
||||
|
||||
self.log.warning(
|
||||
f"Review upload failed ({attempt}/{max_retries})"
|
||||
f" after {time.time() - start}s."
|
||||
f" Retrying in {wait_time}s...",
|
||||
exc_info=True,
|
||||
)
|
||||
time.sleep(wait_time)
|
||||
|
||||
# Exhausted retries - raise a user-friendly validation error with help
|
||||
raise PublishXmlValidationError(
|
||||
self,
|
||||
(
|
||||
"Upload of thumbnail timed out or failed after multiple"
|
||||
" attempts. Please try publishing again."
|
||||
),
|
||||
formatting_data={
|
||||
"upload_type": "Thumbnail",
|
||||
"file": repre_path,
|
||||
"error": str(last_error),
|
||||
},
|
||||
help_filename="upload_file.xml",
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue