Don't try failover for canary

No point trying, it's the same lambda. As `_invoke_lambda` currently
takes a bytes payload, rather than a json payload, it meant the decision
between encoding the payload in the canary or moving the encoding into
the `_invoke_lambda` function. We decided to go for the former as the
lesser of two evils. We may end up doing the encoding twice in the case
of a failover but this avoids us having to put the encoding in our code
in several places (for example the canary and also soon to be the link
tests).
This commit is contained in:
David McDonald
2021-01-14 10:45:49 +00:00
parent b5a33ded98
commit 3216a74fbd

View File

@@ -109,17 +109,17 @@ class CBCProxyClientBase(ABC):
pass
def _invoke_lambda_with_failover(self, payload):
payload_bytes = bytes(json.dumps(payload), encoding='utf8')
result = self._invoke_lambda(self.lambda_name, payload_bytes)
result = self._invoke_lambda(self.lambda_name, payload)
if not result:
failover_result = self._invoke_lambda(self.failover_lambda_name, payload_bytes)
failover_result = self._invoke_lambda(self.failover_lambda_name, payload)
if not failover_result:
raise CBCProxyException(f'Lambda failed for both {self.lambda_name} and {self.failover_lambda_name}')
return result
def _invoke_lambda(self, lambda_name, payload_bytes):
def _invoke_lambda(self, lambda_name, payload):
payload_bytes = bytes(json.dumps(payload), encoding='utf8')
current_app.logger.info(f"Calling lambda {lambda_name}")
result = self._lambda_client.invoke(
FunctionName=lambda_name,
@@ -168,7 +168,7 @@ class CBCProxyCanary(CBCProxyClientBase):
self,
identifier,
):
self._invoke_lambda_with_failover(payload={'identifier': identifier})
self._invoke_lambda(self.lambda_name, payload={'identifier': identifier})
class CBCProxyEE(CBCProxyClientBase):