Skip to content

Commit c98d848

Browse files
authored
Merge pull request #15 from rafalkrupinski/feature/add_nats_result_backend
add nats result backend - continuation
2 parents d9d10b4 + 2190328 commit c98d848

File tree

14 files changed

+767
-645
lines changed

14 files changed

+767
-645
lines changed

.github/workflows/test.yaml

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,34 @@ name: Testing taskiq-nats
33
on: pull_request
44

55
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:
6+
lint:
7+
strategy:
8+
matrix:
9+
cmd:
10+
- black
11+
- ruff
12+
- mypy
3513
runs-on: ubuntu-latest
3614
steps:
37-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v4
16+
- name: Install poetry
17+
run: pipx install poetry
3818
- name: Set up Python
39-
uses: actions/setup-python@v2
19+
uses: actions/setup-python@v4
4020
with:
41-
python-version: "3.9"
21+
python-version: "3.11"
22+
cache: "poetry"
4223
- 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 .
24+
run: poetry install
25+
- name: Run lint check
26+
run: poetry run pre-commit run -a ${{ matrix.cmd }}
4827
pytest:
4928
strategy:
5029
matrix:
51-
py_version: ["3.8", "3.9", "3.10", "3.11"]
30+
py_version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
5231
runs-on: "ubuntu-latest"
5332
steps:
54-
- uses: actions/checkout@v2
33+
- uses: actions/checkout@v4
5534
- name: Set up Python
5635
uses: actions/setup-python@v2
5736
with:

.pre-commit-config.yaml

Lines changed: 33 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,40 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
4-
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v2.4.0
6-
hooks:
7-
- id: check-ast
8-
- id: trailing-whitespace
9-
- id: check-toml
10-
- id: end-of-file-fixer
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v2.4.0
6+
hooks:
7+
- id: check-ast
8+
- id: trailing-whitespace
9+
- id: check-toml
10+
- id: end-of-file-fixer
1111

12-
- repo: https://github.com/asottile/add-trailing-comma
13-
rev: v2.1.0
14-
hooks:
15-
- id: add-trailing-comma
12+
- repo: https://github.com/asottile/add-trailing-comma
13+
rev: v2.1.0
14+
hooks:
15+
- id: add-trailing-comma
1616

17-
- repo: local
18-
hooks:
19-
- id: black
20-
name: Format with Black
21-
entry: poetry run black
22-
language: system
23-
types: [python]
17+
- repo: local
18+
hooks:
19+
- id: black
20+
name: Format with Black
21+
entry: poetry run black
22+
language: system
23+
types: [ python ]
2424

25-
- id: autoflake
26-
name: autoflake
27-
entry: poetry run autoflake
28-
language: system
29-
types: [python]
30-
args: [--in-place, --remove-all-unused-imports, --remove-duplicate-keys]
25+
- repo: https://github.com/astral-sh/ruff-pre-commit
26+
rev: v0.6.0
27+
hooks:
28+
- id: ruff
29+
name: ruff-check
30+
pass_filenames: false
31+
args:
32+
- --fix
33+
- taskiq_nats
34+
- tests
3135

32-
- id: isort
33-
name: isort
34-
entry: poetry run isort
35-
language: system
36-
types: [python]
37-
38-
- id: flake8
39-
name: Check with Flake8
40-
entry: poetry run flake8
41-
language: system
42-
pass_filenames: false
43-
types: [python]
44-
args: [--count, taskiq_nats, tests]
45-
46-
- id: mypy
47-
name: Validate types with MyPy
48-
entry: poetry run mypy
49-
language: system
50-
pass_filenames: false
51-
types: [python]
52-
args: [taskiq_nats, tests]
53-
54-
- id: yesqa
55-
name: Remove usless noqa
56-
entry: poetry run yesqa
57-
language: system
58-
types: [python]
36+
- repo: https://github.com/pre-commit/mirrors-mypy
37+
rev: v1.11.1
38+
hooks:
39+
- id: mypy
40+
pass_filenames: false

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,40 @@ Here's the constructor parameters:
119119
* `durable` - durable name of the consumer. It's used to share messages between different consumers.
120120
* `pull_consume_batch` - maximum number of message that can be fetched each time.
121121
* `pull_consume_timeout` - timeout for messages fetch. If there is no messages, we start fetching messages again.
122+
123+
124+
## NATS Result Backend
125+
It's possible to use NATS JetStream to store tasks result.
126+
```python
127+
import asyncio
128+
from taskiq_nats import PullBasedJetStreamBroker
129+
from taskiq_nats.result_backend import NATSObjectStoreResultBackend
130+
131+
132+
result_backend = NATSObjectStoreResultBackend(
133+
servers="localhost",
134+
)
135+
broker = PullBasedJetStreamBroker(
136+
servers="localhost",
137+
).with_result_backend(
138+
result_backend=result_backend,
139+
)
140+
141+
142+
@broker.task
143+
async def awesome_task() -> str:
144+
return "Hello, NATS!"
145+
146+
147+
async def main() -> None:
148+
await broker.startup()
149+
task = await awesome_task.kiq()
150+
res = await task.wait_result()
151+
print(res)
152+
await broker.shutdown()
153+
154+
155+
if __name__ == "__main__":
156+
asyncio.run(main())
157+
158+
```

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ version: '3.7'
55
# successfully.
66
services:
77
nats:
8-
image: nats:2.9.15-alpine
8+
image: nats:2.10.12-alpine
99
command:
1010
- "-m"
1111
- "8222"

0 commit comments

Comments
 (0)