Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion mhs/common/mhs_common/routing/sds_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ def _set_identifier_value(resource, system, value):
def _get_extension(endpoint, system, value_key):
def _get_extensions(resource):
return list(filter(lambda kv: kv['url'] == 'https://fhir.nhs.uk/StructureDefinition/Extension-SDS-ReliabilityConfiguration', resource['extension']))[0]['extension']
return list(filter(lambda kv: kv['url'] == system, _get_extensions(endpoint)))[0][value_key]
extensions_matching_system = list(filter(lambda kv: kv['url'] == system, _get_extensions(endpoint)))
if len(extensions_matching_system) > 0:
return extensions_matching_system[0][value_key]
return None

async def _get_endpoint_resource(self, interaction_id: str, ods_code: str = None) -> Dict:
if not ods_code:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ async def handle_outbound_message(self, from_asid: Optional[str],

reliability_details = await self._lookup_reliability_details(interaction_details,
interaction_details.get('ods-code'))
retry_interval_xml_datetime = reliability_details[common_asynchronous.MHS_RETRY_INTERVAL]
try:
retry_interval = DateUtilities.convert_xml_date_time_format_to_seconds(retry_interval_xml_datetime)
except isoerror.ISO8601Error:
await wdo.set_outbound_status(wd.MessageStatus.OUTBOUND_MESSAGE_PREPARATION_FAILED)
return 500, 'Error when converting retry interval: {} to seconds'.format(retry_interval_xml_datetime), None

error, http_headers, message = await self._serialize_outbound_message(message_id, correlation_id,
interaction_details,
Expand All @@ -74,7 +68,7 @@ async def handle_outbound_message(self, from_asid: Optional[str],
return error[0], error[1], None

return await self._make_outbound_request_with_retries_and_handle_response(url, http_headers, message, wdo,
reliability_details, retry_interval)
reliability_details)

@timing.time_function
async def handle_unsolicited_inbound_message(self, message_id: str, correlation_id: str, message_data: MessageData):
Expand Down
19 changes: 10 additions & 9 deletions mhs/common/mhs_common/workflow/asynchronous_reliable.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ async def handle_outbound_message(self, from_asid: Optional[str],
return 500, 'Error obtaining outbound URL', None

reliability_details = await self._lookup_reliability_details(interaction_details)
retry_interval_xml_datetime = reliability_details[common_asynchronous.MHS_RETRY_INTERVAL]
try:
retry_interval = DateUtilities.convert_xml_date_time_format_to_seconds(retry_interval_xml_datetime)
except isoerror.ISO8601Error:
await wdo.set_outbound_status(wd.MessageStatus.OUTBOUND_MESSAGE_PREPARATION_FAILED)
return 500, 'Error when converting retry interval: {} to seconds'.format(retry_interval_xml_datetime), None

error, http_headers, message = await self._serialize_outbound_message(message_id, correlation_id,
interaction_details,
Expand All @@ -78,12 +72,12 @@ async def handle_outbound_message(self, from_asid: Optional[str],
return error[0], error[1], None

return await self._make_outbound_request_with_retries_and_handle_response(url, http_headers, message, wdo,
reliability_details, retry_interval)
reliability_details)

async def _make_outbound_request_with_retries_and_handle_response(self, url: str, http_headers: Dict[str, str],
message: str, wdo: wd.WorkDescription,
reliability_details: dict, retry_interval: float):
num_of_retries = int(reliability_details[common_asynchronous.MHS_RETRIES])
reliability_details: dict):
num_of_retries = int(reliability_details[common_asynchronous.MHS_RETRIES] or 0)

# retries_remaining is a mutable integer. This is done by putting an (immutable) integer into
# a mutable container.
Expand All @@ -98,6 +92,13 @@ async def _make_outbound_request_with_retries_and_handle_response(self, url: str
handle_error_response)
except _NeedToRetryException:
retries_remaining[0] -= 1
retry_interval_xml_datetime = reliability_details[common_asynchronous.MHS_RETRY_INTERVAL]
try:
retry_interval = DateUtilities.convert_xml_date_time_format_to_seconds(retry_interval_xml_datetime)
except isoerror.ISO8601Error:
await wdo.set_outbound_status(wd.MessageStatus.OUTBOUND_MESSAGE_PREPARATION_FAILED)
return 500, 'Error when converting retry interval: {} to seconds'.format(retry_interval_xml_datetime), None

logger.info("Waiting for {retry_interval} seconds before next request attempt.",
fparams={"retry_interval": retry_interval})
await asyncio.sleep(retry_interval)
Expand Down