Complete the code to set a timeout for a microservice call.
response = service.call(request, timeout=[1])The timeout value should be specified as an integer representing milliseconds. Here, '5' is ambiguous, but typically timeout values are integers like 5000 for 5 seconds. '5000ms' as a string may not be accepted by all APIs.
Complete the code to handle a timeout exception in a microservice call.
try: response = service.call(request, timeout=3000) except [1]: handle_timeout()
The correct exception to catch when a timeout occurs is usually 'TimeoutError'.
Fix the error in the timeout retry logic code.
for attempt in range(3): try: response = service.call(request, timeout=2000) break except [1]: if attempt == 2: raise wait_before_retry()
The correct exception to catch for timeouts is 'TimeoutError'. Other names may not be recognized and cause runtime errors.
Fill both blanks to implement a timeout pattern with fallback and logging.
try: response = service.call(request, timeout=[1]) except [2]: log_timeout() response = fallback_service.call(request)
The timeout is set to 3000 milliseconds and the exception caught is TimeoutError to handle timeout cases properly.
Fill all three blanks to create a timeout pattern with retry, timeout value, and exception handling.
for i in range([1]): try: response = service.call(request, timeout=[2]) break except [3]: if i == [1] - 1: raise wait_before_retry()
The code retries 3 times with a 2000 ms timeout and catches TimeoutError to handle timeout exceptions properly.