| 208 | return True |
| 209 | |
| 210 | def call(self, max_retry=15): |
| 211 | request_callers = self._pop_request_callers() |
| 212 | if not self.can_call(): |
| 213 | return False # currently this is never ran, exceptions are raised before |
| 214 | |
| 215 | request_timestamp = None |
| 216 | api_req_method_list = self._req_method_list |
| 217 | result = None |
| 218 | try_cnt = 0 |
| 219 | throttling_retry = 0 |
| 220 | unexpected_response_retry = 0 |
| 221 | while True: |
| 222 | request_timestamp = self.throttle_sleep() |
| 223 | # self._call internally clear this field, so save it |
| 224 | self._req_method_list = [req_method for req_method in api_req_method_list] |
| 225 | should_throttle_retry = False |
| 226 | should_unexpected_response_retry = False |
| 227 | hashing_offline = False |
| 228 | |
| 229 | try: |
| 230 | result = self._call() |
| 231 | except ServerSideRequestThrottlingException: |
| 232 | should_throttle_retry = True |
| 233 | except HashingOfflineException: |
| 234 | hashing_offline = True |
| 235 | except UnexpectedResponseException: |
| 236 | should_unexpected_response_retry = True |
| 237 | except: |
| 238 | should_unexpected_response_retry = True |
| 239 | |
| 240 | if hashing_offline: |
| 241 | self.logger.warning('Hashing server issue, retrying in 5 Secs...') |
| 242 | sleep(5) |
| 243 | continue |
| 244 | |
| 245 | if should_throttle_retry: |
| 246 | throttling_retry += 1 |
| 247 | if throttling_retry >= max_retry: |
| 248 | raise ServerSideRequestThrottlingException('Server throttled too many times') |
| 249 | sleep(1) # huge sleep ? |
| 250 | continue # skip response checking |
| 251 | |
| 252 | if should_unexpected_response_retry: |
| 253 | unexpected_response_retry += 1 |
| 254 | if unexpected_response_retry >= 5: |
| 255 | self.logger.warning( |
| 256 | 'Server is not responding correctly to our requests. Waiting for 30 seconds to reconnect.') |
| 257 | sleep(30) |
| 258 | else: |
| 259 | sleep(2) |
| 260 | continue |
| 261 | |
| 262 | if not self.is_response_valid(result, request_callers): |
| 263 | try_cnt += 1 |
| 264 | if try_cnt > 3: |
| 265 | self.logger.warning( |
| 266 | 'Server seems to be busy or offline - try again - {}/{}'.format(try_cnt, max_retry)) |
| 267 | if try_cnt >= max_retry: |