Skip to content

Commit

Permalink
Small cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Elena Kolevska <[email protected]>
  • Loading branch information
elena-kolevska committed Oct 21, 2024
1 parent c0c116c commit ed69ed8
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions dapr/clients/grpc/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,16 @@ def next_message(self):
@return: The next message from the queue,
or None if no message is received within the timeout.
"""
if not self._is_stream_active():
if not self._is_stream_active() or self._stream is None:
raise StreamInactiveError('Stream is not active')


try:
# Read the next message from the stream directly
if self._stream is not None:
message = next(self._stream, None)
if message is None:
return None
return SubscriptionMessage(message.event_message)
message = next(self._stream)
return SubscriptionMessage(message.event_message)
except RpcError as e:
# If Dapr can't be reached, wait until it's ready and reconnect the stream
if e.code() == StatusCode.UNAVAILABLE:
print(
f'gRPC error while reading from stream: {e.details()}, Status Code: {e.code()}'
Expand All @@ -95,7 +94,6 @@ def next_message(self):
except Exception as e:
raise Exception(f'Error while fetching message: {e}')

return None

def respond(self, message, status):
try:
Expand Down

0 comments on commit ed69ed8

Please sign in to comment.