Skip to content

Commit b4d86fd

Browse files
committed
Fixed some errors.
Signed-off-by: Pavel Kirilin <win10@list.ru>
1 parent 68e1178 commit b4d86fd

3 files changed

Lines changed: 57 additions & 8 deletions

File tree

poetry.lock

Lines changed: 45 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pre-commit = "^3.1.1"
1818
mypy = "^1.1.1"
1919
flake8 = "^4.0.0"
2020
wemake-python-styleguide = "^0.17.0"
21+
autoflake = "^1.4"
22+
yesqa = "^1.4.0"
2123

2224
[build-system]
2325
requires = ["poetry-core"]

taskiq_nats/broker.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
from logging import getLogger
12
from typing import Any, AsyncGenerator, Callable, Optional, TypeVar, Union
2-
from taskiq import AsyncBroker, AsyncResultBackend, BrokerMessage
33

44
from nats.aio.client import Client
5+
from taskiq import AsyncBroker, AsyncResultBackend, BrokerMessage
6+
7+
_T = TypeVar("_T") # noqa: WPS111 (Too short)
8+
59

6-
_T = TypeVar("_T")
10+
logger = getLogger("taskiq_nats")
711

812

913
class NatsBroker(AsyncBroker):
10-
def __init__(
14+
def __init__( # noqa: WPS211 (too many args)
1115
self,
1216
servers: Union[str, list[str]],
1317
subject: str = "tasiq_tasks",
@@ -35,13 +39,12 @@ async def kick(self, message: BrokerMessage) -> None:
3539
)
3640

3741
async def listen(self) -> AsyncGenerator[BrokerMessage, None]:
38-
subscribe = await self.client.subscribe(self.subject, queue=self.queue)
42+
subscribe = await self.client.subscribe(self.subject, queue=self.queue or "")
3943
async for message in subscribe.messages:
4044
try:
41-
message = BrokerMessage.parse_raw(message.data)
42-
yield message
45+
yield BrokerMessage.parse_raw(message.data)
4346
except ValueError:
44-
continue
47+
logger.warning(f"Cannot parse message: {message.data.decode('utf-8')}")
4548

4649
async def shutdown(self) -> None:
4750
await self.client.close()

0 commit comments

Comments
 (0)