♻️ refactor function name and remove speedcopy fallback

This commit is contained in:
Ondřej Samohel 2025-05-09 17:15:38 +02:00
parent 0d7ced6fc6
commit ee7d045413
No known key found for this signature in database
GPG key ID: 02376E18990A97C6
2 changed files with 10 additions and 19 deletions

View file

@ -1,18 +1,13 @@
import concurrent.futures
import os
import logging
import sys
import errno
from concurrent.futures import ThreadPoolExecutor, Future
from typing import List, Optional
from ayon_core.lib import create_hard_link
# this is needed until speedcopy for linux is fixed
if sys.platform == "win32":
from speedcopy import copyfile
else:
from shutil import copyfile
from speedcopy import copyfile
class DuplicateDestinationError(ValueError):
@ -118,7 +113,7 @@ class FileTransaction:
executor.submit(self._backup_file, dst, src)
for dst, (src, _) in self._transfers.items()
]
as_completed_stop_and_raise_on_error(
wait_for_future_errors(
executor, backup_futures, logger=self.log)
# Submit transfer tasks
@ -126,7 +121,7 @@ class FileTransaction:
executor.submit(self._transfer_file, dst, src, opts)
for dst, (src, opts) in self._transfers.items()
]
as_completed_stop_and_raise_on_error(
wait_for_future_errors(
executor, transfer_futures, logger=self.log)
def _backup_file(self, dst, src):
@ -228,7 +223,7 @@ class FileTransaction:
return src == dst
def as_completed_stop_and_raise_on_error(
def wait_for_future_errors(
executor: ThreadPoolExecutor,
futures: List[Future],
logger: Optional[logging.Logger] = None):
@ -237,7 +232,7 @@ def as_completed_stop_and_raise_on_error(
The ThreadPoolExecutor only cancels pending futures on exception but will
still complete those that are running - each which also themselves could
fail. We log all exceptions, but re-raise the last exception only.
fail. We log all exceptions but re-raise the last exception only.
"""
if logger is None:
logger = logging.getLogger(__name__)
@ -246,7 +241,7 @@ def as_completed_stop_and_raise_on_error(
exception = future.exception()
if exception:
# As soon as an error occurs, stop executing more futures.
# Running workers however, will still complete so we also want
# Running workers, however, will still be complete, so we also want
# to log those errors if any occurred on them.
executor.shutdown(wait=True, cancel_futures=True)
break

View file

@ -3,13 +3,9 @@ import copy
import errno
import itertools
import shutil
import sys
from concurrent.futures import ThreadPoolExecutor
# this is needed until speedcopy for linux is fixed
if sys.platform == "win32":
from speedcopy import copyfile
else:
from shutil import copyfile
from speedcopy import copyfile
import clique
import pyblish.api
@ -21,7 +17,7 @@ from ayon_api.operations import (
from ayon_api.utils import create_entity_id
from ayon_core.lib import create_hard_link, source_hash
from ayon_core.lib.file_transaction import as_completed_stop_and_raise_on_error
from ayon_core.lib.file_transaction import wait_for_future_errors
from ayon_core.pipeline.publish import (
get_publish_template_name,
OptionalPyblishPluginMixin,
@ -431,7 +427,7 @@ class IntegrateHeroVersion(
src_to_dst_file_paths, other_file_paths_mapping
)
]
as_completed_stop_and_raise_on_error(executor, futures)
wait_for_future_errors(executor, futures)
# Update prepared representation etity data with files
# and integrate it to server.