Skip to content

Commit 83bae57

Browse files
committed
Repo is updated for release.
Signed-off-by: Pavel Kirilin <[email protected]>
1 parent 36be6f6 commit 83bae57

File tree

10 files changed

+689
-7
lines changed

10 files changed

+689
-7
lines changed

.flake8

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ per-file-ignores =
8383
test_*.py,tests.py,tests_*.py,*/tests/*:
8484
; Use of assert detected
8585
S101,
86+
; Found outer scope names shadowing.
87+
WPS442,
88+
; Found direct magic attribute usage.
89+
WPS609,
90+
; Found protected attribute usage
91+
WPS437,
8692

8793
exclude =
8894
./.git,

.github/workflows/release.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Release python package
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Set up Python
14+
uses: actions/setup-python@v2
15+
with:
16+
python-version: "3.9"
17+
- name: Install deps
18+
uses: knowsuchagency/poetry-install@v1
19+
env:
20+
POETRY_VIRTUALENVS_CREATE: false
21+
- name: Release package
22+
env:
23+
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
24+
run: poetry publish --build

.github/workflows/test.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Testing taskiq-aio-pika
2+
3+
on: push
4+
5+
jobs:
6+
black:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- name: Set up Python
11+
uses: actions/setup-python@v2
12+
with:
13+
python-version: "3.9"
14+
- name: Install deps
15+
uses: knowsuchagency/poetry-install@v1
16+
env:
17+
POETRY_VIRTUALENVS_CREATE: false
18+
- name: Run black check
19+
run: poetry run black --check .
20+
flake8:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v2
24+
- name: Set up Python
25+
uses: actions/setup-python@v2
26+
with:
27+
python-version: "3.9"
28+
- name: Install deps
29+
uses: knowsuchagency/poetry-install@v1
30+
env:
31+
POETRY_VIRTUALENVS_CREATE: false
32+
- name: Run flake8 check
33+
run: poetry run flake8 --count .
34+
mypy:
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v2
38+
- name: Set up Python
39+
uses: actions/setup-python@v2
40+
with:
41+
python-version: "3.9"
42+
- name: Install deps
43+
uses: knowsuchagency/poetry-install@v1
44+
env:
45+
POETRY_VIRTUALENVS_CREATE: false
46+
- name: Run mypy check
47+
run: poetry run mypy .
48+
pytest:
49+
services:
50+
rabbit:
51+
image: rabbitmq:3.9.16-alpine
52+
env:
53+
RABBITMQ_DEFAULT_USER: "guest"
54+
RABBITMQ_DEFAULT_PASS: "guest"
55+
RABBITMQ_DEFAULT_VHOST: "/"
56+
options: >-
57+
--health-cmd="rabbitmq-diagnostics check_running -q"
58+
--health-interval=10s
59+
--health-timeout=5s
60+
--health-retries=8
61+
ports:
62+
- 5672:5672
63+
strategy:
64+
matrix:
65+
py_version: ["3.7", "3.8", "3.9", "3.10"]
66+
os: [ubuntu-latest, windows-latest]
67+
runs-on: "${{ matrix.os }}"
68+
steps:
69+
- uses: actions/checkout@v2
70+
- name: Set up Python
71+
uses: actions/setup-python@v2
72+
with:
73+
python-version: "${{ matrix.py_version }}"
74+
- name: Update pip
75+
run: python -m pip install -U pip
76+
- name: Install poetry
77+
run: python -m pip install poetry
78+
- name: Install deps
79+
run: poetry install
80+
env:
81+
POETRY_VIRTUALENVS_CREATE: false
82+
- name: Run pytest check
83+
run: poetry run pytest -vv -n auto --cov="taskiq_aio_pika" .

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,20 @@ broker = AioPikaBroker()
1212
async def test() -> None:
1313
print("nothing")
1414

15-
```
15+
```
16+
17+
18+
## Configuration
19+
20+
AioPikaBroker parameters:
21+
`url` - url to rabbitmq. If None, "amqp://guest:guest@localhost:5672" is used.
22+
`result_backend` - custom result backend.
23+
`task_id_generator` - custom task_id genertaor.
24+
`exchange_name` - name of exchange that used to send messages.
25+
`exchange_type` - type of the exchange. Used only if `declare_exchange` is True.
26+
`queue_name` - queue that used to get incoming messages.
27+
`routing_key` - that used to bind that queue to the exchange.
28+
`declare_exchange` - whether you want to declare new exchange if it doesn't exist.
29+
`qos` - number of messages that worker can prefetch.
30+
`max_connection_pool_size` - maximum number of connections in pool.
31+
`max_channel_pool_size` - maximum number of channels for each connection.

poetry.lock

Lines changed: 210 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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.poetry]
22
name = "taskiq-aio-pika"
33
version = "0.0.1"
4-
description = ""
4+
description = "RabbitMQ broker for taskiq"
55
authors = ["Pavel Kirilin <[email protected]>"]
66
readme = "README.md"
77

@@ -20,6 +20,9 @@ pre-commit = "^2.20.0"
2020
yesqa = "^1.4.0"
2121
autoflake = "^1.4"
2222
wemake-python-styleguide = "^0.16.1"
23+
pytest-xdist = { version = "^2.5.0", extras = ["psutil"] }
24+
anyio = "^3.6.1"
25+
pytest-cov = "^3.0.0"
2326

2427
[tool.mypy]
2528
strict = true

taskiq_aio_pika/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"""Taskiq integration with aio-pika."""
2-
from taskiq_aio_pika.aio_pika_broker import AioPikaBroker
2+
from taskiq_aio_pika.broker import AioPikaBroker
33

44
__all__ = ["AioPikaBroker"]

taskiq_aio_pika/aio_pika_broker.py renamed to taskiq_aio_pika/broker.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class AioPikaBroker(AsyncBroker):
1919

2020
def __init__( # noqa: WPS211
2121
self,
22+
url: Optional[str] = None,
2223
result_backend: Optional[AsyncResultBackend[_T]] = None,
2324
task_id_generator: Optional[Callable[[], str]] = None,
2425
qos: int = 10,
@@ -29,13 +30,39 @@ def __init__( # noqa: WPS211
2930
queue_name: str = "taskiq",
3031
declare_exchange: bool = True,
3132
routing_key: str = "#",
32-
*connection_args: Any,
33+
exchange_type: ExchangeType = ExchangeType.TOPIC,
3334
**connection_kwargs: Any,
3435
) -> None:
36+
"""
37+
Construct a new broker.
38+
39+
:param url: url to rabbitmq. If None,
40+
the default "amqp://guest:guest@localhost:5672" is used.
41+
:param result_backend: custom result backend.
42+
43+
:param task_id_generator: custom task_id genertaor.
44+
:param qos: number of messages that worker can prefetch.
45+
:param loop: specific even loop.
46+
:param max_channel_pool_size: maximum number of channels for each connection.
47+
:param max_connection_pool_size: maximum number of connections in pool.
48+
:param exchange_name: name of exchange that used to send messages.
49+
:param queue_name: queue that used to get incoming messages.
50+
:param declare_exchange: whether you want to declare new exchange
51+
if it doesn't exist.
52+
:param routing_key: that used to bind that queue to the exchange.
53+
:param exchange_type: type of the exchange.
54+
Used only if `declare_exchange` is True.
55+
:param connection_kwargs: additional keyword arguments,
56+
for connect_robust method of aio-pika.
57+
"""
3558
super().__init__(result_backend, task_id_generator)
3659

3760
async def _get_rmq_connection() -> AbstractRobustConnection:
38-
return await connect_robust(*connection_args, **connection_kwargs)
61+
return await connect_robust(
62+
url,
63+
loop=loop,
64+
**connection_kwargs,
65+
)
3966

4067
self._connection_pool: Pool[AbstractRobustConnection] = Pool(
4168
_get_rmq_connection,
@@ -54,6 +81,7 @@ async def get_channel() -> AbstractChannel:
5481
)
5582

5683
self._exchange_name = exchange_name
84+
self._exchange_type = exchange_type
5785
self._qos = qos
5886
self._declare_exchange = declare_exchange
5987
self._queue_name = queue_name
@@ -65,7 +93,7 @@ async def startup(self) -> None:
6593
if self._declare_exchange:
6694
exchange = await channel.declare_exchange(
6795
self._exchange_name,
68-
type=ExchangeType.TOPIC,
96+
type=self._exchange_type,
6997
)
7098
else:
7199
exchange = await channel.get_exchange(self._exchange_name, ensure=False)

0 commit comments

Comments
 (0)