fix: defer slow Syncthing rescans

This commit is contained in:
2026-07-24 16:13:39 +00:00
parent 57acc90363
commit 053b0135b3
7 changed files with 39 additions and 8 deletions
+18 -2
View File
@@ -4,6 +4,7 @@ from __future__ import annotations
import hashlib
import json
import logging
import os
import shutil
import stat
@@ -27,7 +28,7 @@ from archive_clients.qbittorrent import (
)
from archive_clients.resources import NormalizedResource
from archive_clients.state import ClientStore
from archive_clients.syncthing import SyncthingTransferObserver
from archive_clients.syncthing import RouteSetupError, SyncthingTransferObserver
from archive_clients.transfer import (
TransferError,
TransferIntegrityError,
@@ -53,6 +54,9 @@ class JobCancelled(JobExecutionError):
pass
logger = logging.getLogger(__name__)
class ClientJobExecutor:
def __init__(
self,
@@ -579,7 +583,17 @@ class ClientJobExecutor:
f"staged {completed} of {total} bytes",
),
)
self._observer(definition).rescan()
try:
self._observer(definition).rescan()
except RouteSetupError as exc:
# A manual Syncthing scan may take longer than the bounded REST
# request timeout for a large newly linked file. The folder watch
# and the following transfer observation still converge, so do
# not roll back an otherwise durable staged transfer.
logger.warning("syncthing_rescan_deferred", extra={
"job_id": definition.job_id,
"error_type": type(exc).__name__,
})
def _wait_for_syncthing(
self,
@@ -1145,6 +1159,8 @@ def _job_error_code(error: Exception) -> int:
return common_pb2.ERROR_CODE_INTEGRITY_CHECK_FAILED
if isinstance(error, PermissionError):
return common_pb2.ERROR_CODE_PERMISSION_DENIED
if isinstance(error, RouteSetupError):
return common_pb2.ERROR_CODE_UNAVAILABLE
if isinstance(error, JobExecutionError):
return common_pb2.ERROR_CODE_PRECONDITION_FAILED
if isinstance(error, TransferError):