mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 23:41:17 -05:00
Retry with failover lambda for FunctionError and status > 299
For all FunctionErrors, and for invoke errors (status > 299) we want to retry with failover lambda. We are doing this, because if there is a connection or other error with one lambda, the failover lambda may still work and it's worth trying. With time, we will probably have more complex retry flow, depending on the error and even maybe differing for each MNO (broadcast provider).
This commit is contained in:
committed by
David McDonald
parent
1aff854afd
commit
b5a33ded98
@@ -112,12 +112,10 @@ class CBCProxyClientBase(ABC):
|
||||
payload_bytes = bytes(json.dumps(payload), encoding='utf8')
|
||||
result = self._invoke_lambda(self.lambda_name, payload_bytes)
|
||||
|
||||
if 'FunctionError' in result:
|
||||
if result['Payload']['errorType'] == "CBCNewConnectionError":
|
||||
current_app.logger.info(f"Got CBCNewConnectionError for {self.lambda_name}, calling failover lambda")
|
||||
result = self._invoke_lambda(self.failover_lambda_name, payload_bytes)
|
||||
else:
|
||||
raise CBCProxyException('Function exited with unhandled exception')
|
||||
if not result:
|
||||
failover_result = self._invoke_lambda(self.failover_lambda_name, payload_bytes)
|
||||
if not failover_result:
|
||||
raise CBCProxyException(f'Lambda failed for both {self.lambda_name} and {self.failover_lambda_name}')
|
||||
|
||||
return result
|
||||
|
||||
@@ -128,12 +126,24 @@ class CBCProxyClientBase(ABC):
|
||||
InvocationType='RequestResponse',
|
||||
Payload=payload_bytes,
|
||||
)
|
||||
current_app.logger.info(f"Finished calling lambda {lambda_name}")
|
||||
|
||||
if result['StatusCode'] > 299:
|
||||
raise CBCProxyException('Could not invoke lambda')
|
||||
current_app.logger.info(
|
||||
f"Error calling lambda {self.lambda_name} with status code { result['StatusCode']}, {result.get('Payload')}"
|
||||
)
|
||||
success = False
|
||||
|
||||
current_app.logger.info(f"Finished calling lambda {lambda_name}")
|
||||
return result
|
||||
elif 'FunctionError' in result:
|
||||
current_app.logger.info(
|
||||
f"Error calling lambda {self.lambda_name} with function error { result['Payload'] }"
|
||||
)
|
||||
success = False
|
||||
|
||||
else:
|
||||
success = True
|
||||
|
||||
return success
|
||||
|
||||
def infer_language_from(self, content):
|
||||
if non_gsm_characters(content):
|
||||
|
||||
Reference in New Issue
Block a user