Skip to content

Commit

Permalink
Merge pull request #575 from jennydaman/change-lonk-types
Browse files Browse the repository at this point in the history
Censor error message and change LonkWsSubscription
  • Loading branch information
jennydaman authored Sep 12, 2024
2 parents e3731fd + 253cdfe commit ce7dabb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions chris_backend/pacsfiles/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ async def _subscribe(self, pacs_name: str, series_instance_uid: str):
response = Lonk(
pacs_name=pacs_name,
SeriesInstanceUID=series_instance_uid,
message=LonkWsSubscription(subscription='subscribed'),
message=LonkWsSubscription(subscribed=True),
)
await self.send_json(response)
except Exception as e:
response = Lonk(
pacs_name=pacs_name,
SeriesInstanceUID=series_instance_uid,
message=LonkWsSubscription(subscription='error'),
message=LonkWsSubscription(subscribed=False),
)
await self.send_json(response)
await self.close(code=500)
Expand Down
10 changes: 7 additions & 3 deletions chris_backend/pacsfiles/lonk.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""
import asyncio
import enum
from sys import byteorder
import logging
from typing import (
Self,
Callable,
Expand All @@ -21,6 +21,8 @@
from nats.aio.subscription import Subscription
from nats.aio.msg import Msg

logger = logging.getLogger(__name__)


class SubscriptionRequest(TypedDict):
"""
Expand Down Expand Up @@ -79,7 +81,7 @@ class LonkWsSubscription(TypedDict):
https://chrisproject.org/docs/oxidicom/lonk-ws#lonk-ws-subscription
"""

subscription: Literal['subscribed', 'error']
subscribed: bool


LonkMessageData = LonkProgress | LonkError | LonkDone | LonkWsSubscription
Expand Down Expand Up @@ -202,7 +204,9 @@ def _serialize_to_lonkws(payload: bytes) -> LonkMessageData:
ndicom = int.from_bytes(data, 'little', signed=False)
return LonkProgress(ndicom=ndicom)
case LonkMagicByte.ERROR.value:
error = data.decode(encoding='utf-8')
msg = data.decode(encoding='utf-8')
logger.error(f'Error from oxidicom: {msg}')
error = 'oxidicom reported an error, check logs for details.'
return LonkError(error=error)
case _:
hexstr = ' '.join(hex(b) for b in payload)
Expand Down
7 changes: 4 additions & 3 deletions chris_backend/pacsfiles/tests/test_consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async def test_lonk_ws(self):
self.assertEqual(
await communicator.receive_json_from(),
Lonk(
message=LonkWsSubscription(subscription='subscribed'),
message=LonkWsSubscription(subscribed=True),
**series1,
),
)
Expand All @@ -69,7 +69,7 @@ async def test_lonk_ws(self):
self.assertEqual(
await communicator.receive_json_from(),
Lonk(
message=LonkWsSubscription(subscription='subscribed'),
message=LonkWsSubscription(subscribed=True),
**series2,
),
)
Expand All @@ -86,9 +86,10 @@ async def test_lonk_ws(self):
)

await oxidicom.send_error(error='stuck in chimney', **series2)
expected = 'oxidicom reported an error, check logs for details.'
self.assertEqual(
await communicator.receive_json_from(),
Lonk(message=LonkError(error='stuck in chimney'), **series2),
Lonk(message=LonkError(error=expected), **series2),
)

await oxidicom.send_progress(ndicom=192, **series1)
Expand Down

0 comments on commit ce7dabb

Please sign in to comment.