Skip to content

Commit 03f162e

Browse files
committed
Merge branch 'release/0.1.0'
2 parents c91d60f + 574dd42 commit 03f162e

File tree

10 files changed

+668
-40
lines changed

10 files changed

+668
-40
lines changed

.github/workflows/release.yaml

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.yaml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Testing taskiq-redis
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+
strategy:
50+
matrix:
51+
py_version: ["3.7", "3.8", "3.9", "3.10"]
52+
runs-on: "ubuntu-latest"
53+
steps:
54+
- uses: actions/checkout@v2
55+
- name: Set up Python
56+
uses: actions/setup-python@v2
57+
with:
58+
python-version: "${{ matrix.py_version }}"
59+
- name: Update pip
60+
run: python -m pip install -U pip
61+
- name: Install poetry
62+
run: python -m pip install poetry
63+
- name: Install deps
64+
run: poetry install
65+
env:
66+
POETRY_VIRTUALENVS_CREATE: false
67+
- name: Update docker-compose
68+
uses: KengoTODA/actions-setup-docker-compose@v1
69+
with:
70+
version: "2.16.0"
71+
- name: docker compose up
72+
run: docker-compose up -d --wait
73+
- name: Run pytest check
74+
run: poetry run pytest -vv -n auto --cov="taskiq_nats" .
75+
- name: Generate report
76+
run: poetry run coverage xml
77+
- name: Upload coverage reports to Codecov with GitHub Action
78+
uses: codecov/codecov-action@v3
79+
if: matrix.py_version == '3.9'
80+
with:
81+
token: ${{ secrets.CODECOV_TOKEN }}
82+
fail_ci_if_error: true
83+
verbose: true
84+
- name: Stop containers
85+
if: always()
86+
run: docker-compose down

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Taskiq NATS
2+
3+
Taskiq-nats is a plugin for taskiq that adds NATS broker.
4+
5+
## Installation
6+
7+
To use this project you must have installed core taskiq library:
8+
9+
```bash
10+
pip install taskiq taskiq-redis
11+
```
12+
13+
## Usage
14+
15+
Here's a minimal setup example with a broker and one task.
16+
17+
```python
18+
import asyncio
19+
from taskiq_nats import NatsBroker
20+
21+
broker = NatsBroker(
22+
[
23+
"nats://nats1:4222",
24+
"nats://nats2:4222",
25+
],
26+
queue="random_queue_name",
27+
)
28+
29+
30+
@broker.task
31+
async def my_lovely_task():
32+
print("I love taskiq")
33+
34+
35+
async def main():
36+
await broker.startup()
37+
38+
await my_lovely_task.kiq()
39+
40+
await broker.shutdown()
41+
42+
43+
if __name__ == "__main__":
44+
asyncio.run(main())
45+
46+
```
47+
48+
## NatsBroker configuration
49+
50+
Here's the constructor parameters:
51+
52+
* `servers` - a single string or a list of strings with nats nodes addresses.
53+
* `subject` - name of the subect that will be used to exchange tasks betwee workers and clients.
54+
* `queue` - optional name of the queue. By default NatsBroker broadcasts task to all workers,
55+
but if you want to handle every task only once, you need to supply this argument.
56+
* `result_backend` - custom result backend.
57+
* `task_id_generator` - custom function to generate task ids.
58+
* Every other keyword argument will be sent to `nats.connect` function.

docker-compose.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: '3.7'
2+
3+
# This docker compose is used for testing.
4+
# It contains only services required for pytest to run
5+
# successfully.
6+
services:
7+
nats:
8+
image: nats:2.9.15-alpine
9+
command:
10+
- "-m"
11+
- "8222"
12+
- "--debug"
13+
healthcheck:
14+
test:
15+
- "CMD"
16+
- "sh"
17+
- "-c"
18+
- "wget http://localhost:8222/healthz -q -O - | xargs | grep ok || exit 1"
19+
interval: 5s
20+
timeout: 3s
21+
retries: 5
22+
ports:
23+
- 8222:8222
24+
- 4222:4222

0 commit comments

Comments
 (0)