Skip to content

Commit d8568b4

Browse files
committed
Added docs
1 parent d0f325c commit d8568b4

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,64 @@
11
# TaskIQ - PSQLPy
2+
3+
TaskIQ-PSQLPy is a plugin for taskiq that adds a new result backend based on PostgreSQL and [PSQLPy](https://github.com/qaspen-python/psqlpy).
4+
5+
## Installation
6+
To use this project you must have installed core taskiq library:
7+
```bash
8+
pip install taskiq
9+
```
10+
11+
This project can be installed using pip:
12+
```bash
13+
pip install taskiq-psqlpy
14+
```
15+
16+
Or using poetry:
17+
```
18+
poetry add taskiq-psqlpy
19+
```
20+
21+
## Usage
22+
Let's see the example with the redis broker and PostgreSQL PSQLPy result backend:
23+
```python
24+
# broker.py
25+
import asyncio
26+
27+
from taskiq_redis import ListQueueBroker
28+
from taskiq_psqlpy import PSQLPyResultBackend
29+
30+
psqlpy_result_backend = PSQLPyResultBackend(
31+
dsn="postgres://postgres:postgres@localhost:5432/postgres",
32+
)
33+
34+
# Or you can use PubSubBroker if you need broadcasting
35+
broker = ListQueueBroker(
36+
url="redis://localhost:6379",
37+
result_backend=psqlpy_result_backend,
38+
)
39+
40+
41+
@broker.task
42+
async def best_task_ever() -> None:
43+
"""Solve all problems in the world."""
44+
await asyncio.sleep(5.5)
45+
print("All problems are solved!")
46+
47+
48+
async def main():
49+
await broker.startup()
50+
task = await best_task_ever.kiq()
51+
print(await task.wait_result())
52+
await broker.shutdown()
53+
54+
55+
if __name__ == "__main__":
56+
asyncio.run(main())
57+
```
58+
59+
## PSQLPyResultBackend configuration
60+
- `dsn`: connection string to PostgreSQL.
61+
- `keep_results`: flag to not remove results from Redis after reading.
62+
- `table_name`: name of the table in PostgreSQL to store TaskIQ results.
63+
- `field_for_task_id`: type of a field for `task_id`, you may need it if you want to have length of task_id more than 255 symbols.
64+
- `**connect_kwargs`: additional connection parameters, you can read more about it in [PSQLPy](https://github.com/qaspen-python/psqlpy) repository.

taskiq_psqlpy/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from taskiq_psqlpy.result_backend import PSQLPyResultBackend
2+
3+
__all__ = [
4+
"PSQLPyResultBackend",
5+
]

taskiq_psqlpy/result_backend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pickle
2-
from typing import Any, Final, Literal, TypeVar, cast
2+
from typing import Any, Final, Literal, Optional, TypeVar, cast
33

44
from psqlpy import PSQLPool
55
from psqlpy.exceptions import RustPSQLDriverPyBaseError
@@ -23,7 +23,7 @@ class PSQLPyResultBackend(AsyncResultBackend[_ReturnType]):
2323

2424
def __init__(
2525
self,
26-
dsn: str = "postgres://postgres:postgres@localhost:5432/postgres",
26+
dsn: Optional[str] = "postgres://postgres:postgres@localhost:5432/postgres",
2727
keep_results: bool = True,
2828
table_name: str = "taskiq_results",
2929
field_for_task_id: Literal["VarChar", "Text"] = "VarChar",

0 commit comments

Comments
 (0)