Skip to content

Commit 8c3786f

Browse files
committed
Merge branch 'release/0.3.0'
2 parents 82caeb1 + f9079a3 commit 8c3786f

File tree

6 files changed

+269
-250
lines changed

6 files changed

+269
-250
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ repos:
66
hooks:
77
- id: check-ast
88
- id: trailing-whitespace
9+
exclude: 'README.md'
910
- id: check-toml
1011
- id: end-of-file-fixer
1112

poetry.lock

Lines changed: 234 additions & 230 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "taskiq-aio-pika"
3-
version = "0.2.2"
3+
version = "0.3.0"
44
description = "RabbitMQ broker for taskiq"
55
authors = ["Pavel Kirilin <[email protected]>"]
66
readme = "README.md"
@@ -20,8 +20,9 @@ keywords = ["taskiq", "tasks", "distributed", "async", "aio-pika"]
2020

2121
[tool.poetry.dependencies]
2222
python = "^3.7"
23-
taskiq = "^0"
23+
taskiq = ">=0.6.0,<1"
2424
aio-pika = "^9.0"
25+
importlib-metadata = {version = "^4.0.0", python = "<3.8"}
2526

2627
[tool.poetry.dev-dependencies]
2728
pytest = "^7.0"

taskiq_aio_pika/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
"""Taskiq integration with aio-pika."""
22
from taskiq_aio_pika.broker import AioPikaBroker
33

4+
try:
5+
# Python 3.8+
6+
from importlib.metadata import version # noqa: WPS433
7+
except ImportError:
8+
# Python 3.7
9+
from importlib_metadata import version # noqa: WPS433, WPS440
10+
11+
__version__ = version("taskiq-aio-pika")
12+
413
__all__ = ["AioPikaBroker"]

taskiq_aio_pika/broker.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
from aio_pika import DeliveryMode, ExchangeType, Message, connect_robust
77
from aio_pika.abc import AbstractChannel, AbstractQueue, AbstractRobustConnection
8-
from taskiq.abc.broker import AsyncBroker
9-
from taskiq.abc.result_backend import AsyncResultBackend
10-
from taskiq.message import BrokerMessage
8+
from taskiq import AckableMessage, AsyncBroker, AsyncResultBackend, BrokerMessage
119

1210
_T = TypeVar("_T") # noqa: WPS111
1311

@@ -228,21 +226,20 @@ async def kick(self, message: BrokerMessage) -> None:
228226
if self.write_channel is None:
229227
raise ValueError("Please run startup before kicking.")
230228

231-
message_base_params: dict[str, Any] = {
229+
message_base_params: Dict[str, Any] = {
232230
"body": message.message,
233231
"headers": {
234232
"task_id": message.task_id,
235233
"task_name": message.task_name,
236234
**message.labels,
237235
},
238236
"delivery_mode": DeliveryMode.PERSISTENT,
237+
"priority": parse_val(
238+
int,
239+
message.labels.get("priority"),
240+
),
239241
}
240242

241-
message_base_params["priority"] = parse_val(
242-
int,
243-
message.labels.get("priority"),
244-
)
245-
246243
delay: Optional[int] = parse_val(int, message.labels.get("delay"))
247244
rmq_message: Message = Message(**message_base_params)
248245

@@ -268,7 +265,7 @@ async def kick(self, message: BrokerMessage) -> None:
268265
routing_key=self._delay_queue_name,
269266
)
270267

271-
async def listen(self) -> AsyncGenerator[bytes, None]:
268+
async def listen(self) -> AsyncGenerator[AckableMessage, None]:
272269
"""
273270
Listen to queue.
274271
@@ -284,5 +281,8 @@ async def listen(self) -> AsyncGenerator[bytes, None]:
284281
queue = await self.declare_queues(self.read_channel)
285282
async with queue.iterator() as iterator:
286283
async for message in iterator:
287-
async with message.process():
288-
yield message.body
284+
yield AckableMessage(
285+
data=message.body,
286+
ack=message.ack,
287+
reject=message.reject,
288+
)

tests/test_broker.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
import pytest
55
from aio_pika import Channel, Message
66
from aio_pika.exceptions import QueueEmpty
7-
from taskiq import BrokerMessage
7+
from taskiq import AckableMessage, BrokerMessage
8+
from taskiq.utils import maybe_awaitable
89

910
from taskiq_aio_pika.broker import AioPikaBroker
1011

1112

12-
async def get_first_task(broker: AioPikaBroker) -> bytes: # type: ignore
13+
async def get_first_task(broker: AioPikaBroker) -> AckableMessage: # type: ignore
1314
"""
1415
Get first message from the queue.
1516
@@ -46,7 +47,8 @@ async def test_kick_success(broker: AioPikaBroker) -> None:
4647

4748
message = await asyncio.wait_for(get_first_task(broker), timeout=0.4)
4849

49-
assert message == sent.message
50+
assert message.data == sent.message
51+
await maybe_awaitable(message.ack())
5052

5153

5254
@pytest.mark.anyio
@@ -111,7 +113,8 @@ async def test_listen(
111113

112114
message = await asyncio.wait_for(get_first_task(broker), timeout=0.4)
113115

114-
assert message == b"test_message"
116+
assert message.data == b"test_message"
117+
await maybe_awaitable(message.ack())
115118

116119

117120
@pytest.mark.anyio
@@ -133,9 +136,10 @@ async def test_wrong_format(
133136
routing_key=queue_name,
134137
)
135138

136-
msg_bytes = await asyncio.wait_for(get_first_task(broker), 0.4)
139+
message = await asyncio.wait_for(get_first_task(broker), 0.4)
137140

138-
assert msg_bytes == b"wrong"
141+
assert message.data == b"wrong"
142+
await maybe_awaitable(message.ack())
139143

140144
with pytest.raises(QueueEmpty):
141145
await queue.get()

0 commit comments

Comments
 (0)