66# there is an upper limit for chunk size on server, ideally should be requested from there once implemented
77UPLOAD_CHUNK_SIZE = 10 * 1024 * 1024
88
9+ # number of attempts to upload a chunk
10+ UPLOAD_CHUNK_ATTEMPTS = 2
11+
12+ # seconds to wait between attempts of uploading a chunk
13+ UPLOAD_CHUNK_ATTEMPT_WAIT = 5
14+
915# size of the log file part to send (if file is larger only this size from end will be sent)
1016MAX_LOG_FILE_SIZE_TO_SEND = 5 * 1024 * 1024
1117
1218# number of attempts to push changes (in case of network issues etc)
13- PUSH_ATTEMPTS = 12
19+ PUSH_ATTEMPTS = 10
1420
15- # seconds to wait between attempts
21+ # seconds to wait between attempts to push changes
1622PUSH_ATTEMPT_WAIT = 5
1723
18- # seconds to wait between sync callback calls
24+ # seconds to wait between sync callback calls
1925SYNC_CALLBACK_WAIT = 0.01
2026
2127# default URL for submitting logs
@@ -33,7 +39,7 @@ class ErrorCode(Enum):
3339
3440
3541class ClientError (Exception ):
36- def __init__ (self , detail , url = None , server_code = None , server_response = None , http_error = None , http_method = None ):
42+ def __init__ (self , detail : str , url = None , server_code = None , server_response = None , http_error = None , http_method = None ):
3743 self .detail = detail
3844 self .url = url
3945 self .http_error = http_error
@@ -43,8 +49,6 @@ def __init__(self, detail, url=None, server_code=None, server_response=None, htt
4349 self .server_response = server_response
4450
4551 self .extra = None
46- # Param to mark error as candidate for retry sync process
47- self .sync_retry = False
4852
4953 def __str__ (self ):
5054 string_res = f"Detail: { self .detail } \n "
@@ -60,6 +64,35 @@ def __str__(self):
6064 string_res += f"{ self .extra } \n "
6165 return string_res
6266
67+ def is_rate_limit (self ) -> bool :
68+ """Check if error is rate limit error based on server code"""
69+ return self .http_error == 429
70+
71+ def is_blocking_sync (self ) -> bool :
72+ """
73+ Check if error is blocking sync based on server code.
74+ Blocking sync means, that the sync is blocked by another user in server.
75+ """
76+ return self .server_code in [
77+ ErrorCode .AnotherUploadRunning .value ,
78+ ErrorCode .ProjectVersionExists .value ,
79+ ]
80+
81+ def is_retryable_sync (self ) -> bool :
82+ # Check if error is retryable based on server code
83+ if self .is_blocking_sync () or self .is_rate_limit ():
84+ return True
85+
86+ if (
87+ self .http_error
88+ and self .detail
89+ and self .http_error == 400
90+ and ("Another process" in self .detail or "Version mismatch" in self .detail )
91+ ):
92+ return True
93+
94+ return False
95+
6396
6497class LoginError (Exception ):
6598 pass
0 commit comments