Skip to content

Commit

Permalink
fix: channel consumer (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
RaRhAeu authored Oct 17, 2024
1 parent 91c11a7 commit ed34aea
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion eventiq/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.1.6"
__version__ = "1.1.7"
11 changes: 4 additions & 7 deletions eventiq/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,14 @@ def publish(self) -> Publisher:


class ChannelConsumer(Consumer[CloudEventType]):
def __inii__(
def __init__(
self,
channel: MemoryObjectSendStream[tuple[CloudEventType, Callable[[], None]]],
**extra: Any,
) -> None:
name_parts = [socket.gethostname(), str(uuid4())]
base_name = extra.get("name")
if base_name:
name_parts.insert(0, base_name)
name = ":".join(name_parts)
extra["name"] = name
if "name" not in extra:
extra.setdefault("dynamic", True)
extra["name"] = f"{socket.gethostname()}:{uuid4()}"
super().__init__(**extra)
self.channel = channel
self._timeout = to_float(self.timeout) or 10.0
Expand Down
11 changes: 8 additions & 3 deletions eventiq/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,13 @@ async def watch_for_signals(self, scope: CancelScope) -> None:

async def _dispatch(self, event: str, **kwargs: Any) -> None:
message = kwargs.get("message")
for middleware in self.middlewares:
middlewares = (
reversed(self.middlewares)
if event.startswith("after_")
else self.middlewares
)

for middleware in middlewares:
if message and (
middleware.requires is not None
and not isinstance(message, middleware.requires)
Expand Down Expand Up @@ -479,8 +485,7 @@ async def subscription(
consumer_send, user_receive = create_memory_object_stream[
tuple[CloudEvent, Callable[[], None]]
](1)
options["dynamic"] = True
consumer = ChannelConsumer(
consumer: Consumer[CloudEvent] = ChannelConsumer(
channel=consumer_send,
event_type=event_type,
topic=topic,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ dependencies = [
"pytest-repeat",
"pyyaml",
"ruff",
"mypy",
"mypy==1.11.1",
"bandit",
"nats-py",
"aiokafka",
Expand Down

0 comments on commit ed34aea

Please sign in to comment.