Skip to content

Commit

Permalink
Rewrite process_response retries (#753)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertyw authored Nov 9, 2024
1 parent a180d4c commit c2b8ef5
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions silk/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,18 @@ def _process_response(self, request, response):
Logger.debug('Process response done.')

def process_response(self, request, response):
max_attempts = 2
attempts = 1
if getattr(request, 'silk_is_intercepted', False):
while True:
while attempts <= max_attempts:
if attempts > 1:
Logger.debug('Retrying _process_response; attempt %s' % attempts)
try:
self._process_response(request, response)
except (AttributeError, DatabaseError):
Logger.debug('Retrying _process_response')
self._process_response(request, response)
finally:
break
except (AttributeError, DatabaseError):
if attempts >= max_attempts:
Logger.warn('Exhausted _process_response attempts; not processing request')
break
attempts += 1
return response

0 comments on commit c2b8ef5

Please sign in to comment.