Skip to content

Comments

Send worklist item to gateway#972

Merged
steventux merged 6 commits intomainfrom
feat/send-worklist-items-to-gateway
Feb 12, 2026
Merged

Send worklist item to gateway#972
steventux merged 6 commits intomainfrom
feat/send-worklist-items-to-gateway

Conversation

@steventux
Copy link
Contributor

@steventux steventux commented Feb 2, 2026

Description

We send the modality worklist item to the relevant Gateway listener via Azure Relay and this transmission of data should occur out of the request cycle via Relay websocket.
In order to effectively background the process of communicating with the Gateway we need a separate process.

This PR adds a few things which allow this communication to happen:

  • Adds Relay model to hold connection info per gateway. This is associated with a Provider.
  • Adds RelayURI for utility functions for obtaining a relay connection url.
  • Adds RelayService to cache relay connections
  • RelayService sends the worklist item to the gateway via Azure Relay websocket connection.
  • Acknowledgement or exceptions persisted back onto the GatewayAction record.

Jira link

https://nhsd-jira.digital.nhs.uk/browse/DTOSS-12148

Review notes

I've opted for running a finite length event loop in a separate thread in order to "fire and forget" the gateway action payload via the relay connection because long lived websockets require a loop.
The acknowledgement from the gateway updates a record in the db.

This PR does not deal with retrying failed actions. We will review how this might be done with the UCD team.

Review checklist

  • Check database queries are correctly scoped to current_provider

@steventux steventux changed the title Feat/send worklist items to gateway Enqueue / send worklist item to gateway Feb 2, 2026
@steventux steventux marked this pull request as ready for review February 3, 2026 09:37
@steventux steventux requested a review from a team February 3, 2026 10:25
@steventux steventux force-pushed the feat/send-worklist-items-to-gateway branch from 00d97ef to ffa500e Compare February 3, 2026 10:31
@steventux steventux marked this pull request as draft February 3, 2026 10:54
@steventux steventux force-pushed the feat/send-worklist-items-to-gateway branch 2 times, most recently from c7c3612 to 8ac83d5 Compare February 4, 2026 16:42
@steventux steventux changed the title Enqueue / send worklist item to gateway Send worklist item to gateway Feb 4, 2026
@steventux steventux force-pushed the feat/send-worklist-items-to-gateway branch 9 times, most recently from 0f06c45 to 8dd93d7 Compare February 5, 2026 14:25
@steventux steventux marked this pull request as ready for review February 5, 2026 14:25
@steventux steventux force-pushed the feat/send-worklist-items-to-gateway branch from 33676d7 to 8755cf3 Compare February 5, 2026 16:50

Communication uses Azure Relay which relies on websockets.

The `Relay` model defines the connection details for a Gateway. A shared access key should be stored in Azure Key Vault and the `shared_access_key_variable_name` field should be set to the name of the ENV var referencing the secret. (Note that keyvault secrets are hyphen delimited, but ENV vars are underscore delimited).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we get the key in manage_breast_screening/config/.env.tpl?

def _create_action(self) -> GatewayAction:
def _create_action(self) -> GatewayAction | None:
"""Create and persist the gateway action."""
relay = Relay.objects.filter(provider=self.appointment.provider).first()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe RelayService could expose get_relay_for(provider) or some such

Copy link
Contributor Author

@steventux steventux Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, have added Relay.for_provider class method

Copy link
Contributor

@carlosmartinez carlosmartinez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@steventux steventux force-pushed the feat/send-worklist-items-to-gateway branch 2 times, most recently from 9ddc2b7 to c41c486 Compare February 11, 2026 17:44
RelayService provides transport for GatewayAction payloads.
It starts a thread which sends payloads to the gateway and exits,
cleaning up the asyncio process used to communicate via Azure Relay websockets.
The Relay database model holds connection details for each of our gateway connections.
Also remove update_status method as it won't be used.
This commit removes the need to run any async code in a new thread. This has the benefit of better database connection cleanup, safer execution of the websocket async code etc. We will be addressing the failure scenarios for the websocket connection and retrying.
@steventux steventux force-pushed the feat/send-worklist-items-to-gateway branch from c41c486 to 995414b Compare February 12, 2026 13:37
@sonarqubecloud
Copy link

@steventux steventux merged commit 3f6fd8b into main Feb 12, 2026
14 checks passed
@steventux steventux deleted the feat/send-worklist-items-to-gateway branch February 12, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants