Debian Codegraph @

src/globus_sdk/services/transfer/transport.py

raw
1 """
2 Custom retry check collection for the TransferClient that overrides
3 the default check_transient_error
4 """
5
6 from __future__ import annotations
7
8 from globus_sdk.transport import RetryCheck, RetryCheckResult, RetryContext
9 from globus_sdk.transport.default_retry_checks import (
10 DEFAULT_RETRY_CHECKS,
11 check_transient_error,
12 )
13
14
15 def check_transfer_transient_error(ctx: RetryContext) -> RetryCheckResult:
16 """
17 check for transient error status codes which could be resolved by
18 retrying the request. Does not retry ExternalErrors or EndpointErrors
19 as those are unlikely to actually be transient.
20
21 :param ctx: The context object which describes the state of the request and the
22 retries which may already have been attempted
23 """
24 retry_config = ctx.caller_info.retry_config
25 if ctx.response is not None and (
26 ctx.response.status_code in retry_config.transient_error_status_codes
27 ):
28 try:
29 code = ctx.response.json()["code"]
30 except (ValueError, KeyError):
31 code = ""
32
33 for non_retry_code in ("ExternalError", "EndpointError"):
34 if non_retry_code in code:
35 return RetryCheckResult.no_decision
36
37 return RetryCheckResult.do_retry
38
39 return RetryCheckResult.no_decision
40
41
42 # Transfer retry checks are the defaults with the transient error one replaced
43 TRANSFER_DEFAULT_RETRY_CHECKS: tuple[RetryCheck, ...] = tuple(
44 check_transfer_transient_error if check is check_transient_error else check
45 for check in DEFAULT_RETRY_CHECKS
46 )