Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add timeout to controller.py #56

Merged
Merged
Changes from 1 commit
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
17 changes: 12 additions & 5 deletions controller/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,15 +556,22 @@ async def record_with_values(
topic: str,
*,
record_type: Optional[Type[T]] = None,
timeout: float = 5.0, # seconds
**values,
) -> Union[T, Mapping[str, Any]]:
"""Get a record from an event with values matching those passed in."""
try:
event = await self.event_queue.get(
lambda event: event.topic == topic
and all(
[event.payload.get(key) == value for key, value in values.items()]
)
event = await asyncio.wait_for(
self.event_queue.get(
Copy link
Member

Choose a reason for hiding this comment

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

This is really close! As it turns out, the event_queue.get method takes a timeout parameter so we can use that instead of the asyncio.wait_for in this method. (Under the hood, this is exactly what the event_queue.get method is doing so the methodology is good!)

lambda event: event.topic == topic
and all(
[
event.payload.get(key) == value
for key, value in values.items()
]
)
),
timeout=timeout,
)
except asyncio.TimeoutError:
raise ControllerError(
Expand Down
Loading