forked from mtusi2026/mtusi2026lab5
33 lines
1.4 KiB
Python
33 lines
1.4 KiB
Python
"""Ограниченный exponential backoff: jitter сохраняется вместе с новой попыткой."""
|
|
|
|
import errno
|
|
import random
|
|
|
|
from minio.error import S3Error
|
|
|
|
from app.core.jobs import JobSettings
|
|
from app.errors.exceptions import ProcessingError
|
|
|
|
|
|
def retry_delay(settings: JobSettings, cycle_attempt: int) -> float:
|
|
ceiling = min(settings.job_retry_max_seconds, settings.job_retry_seconds * 2 ** min(30, max(0, cycle_attempt - 1)))
|
|
return random.uniform(ceiling / 2, ceiling)
|
|
|
|
|
|
def classify_failure(error: Exception) -> tuple[str, bool]:
|
|
if isinstance(error, ProcessingError):
|
|
return error.code, True
|
|
if isinstance(error, S3Error):
|
|
if error.code in {"NoSuchKey", "NoSuchObject"}:
|
|
return "source_missing", True
|
|
if error.code in {"AccessDenied", "InvalidAccessKeyId", "SignatureDoesNotMatch", "NoSuchBucket"}:
|
|
return "storage_configuration", True
|
|
if error.code in {"InternalError", "SlowDown", "ServiceUnavailable", "RequestTimeout", "Throttling"}:
|
|
return "storage_unavailable", False
|
|
return "storage_rejected", True
|
|
if isinstance(error, TimeoutError):
|
|
return "processing_timeout", False
|
|
if isinstance(error, OSError) and error.errno in {errno.EACCES, errno.EPERM, errno.EROFS, errno.ENOENT}:
|
|
return "processing_configuration", True
|
|
return "processing_unavailable", False
|