Metadata-Version: 2.3
Name: taskiq-asyncpg
Version: 0.2.0
Summary: Asyncpg and PostgreSQL integration for taskiq
Author-email: Jefferson Venceslau <jeff.venceslau@gmail.com>
Keywords: async,asyncpg,distributed,postgresql,result_backend,taskiq,tasks
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.9
Requires-Dist: asyncpg>=0.29.0
Requires-Dist: taskiq>=0.11.7
Description-Content-Type: text/markdown

# TaskIQ - Asyncpg

TaskIQ-Asyncpg is a plugin for taskiq that adds a new result backend based on PostgreSQL and [Asyncpg](https://github.com/MagicStack/asyncpg).

## Installation
To use this project you must have installed core taskiq library:
```bash
pip install taskiq
```

This project can be installed using pip:
```bash
pip install taskiq-asyncpg
```

using poetry:
```bash
poetry add taskiq-asyncpg
```

using rye:
```bash
rye add taskiq-asyncpg
```

## Usage
Let's see the example with the redis broker and PostgreSQL Asyncpg result backend:
```python
# broker.py
import asyncio

from taskiq_redis import ListQueueBroker
from taskiq_asyncpg import AsyncpgResultBackend

asyncpg_result_backend = AsyncpgResultBackend(
    dsn="postgres://postgres:postgres@localhost:5432/postgres",
)

# Or you can use PubSubBroker if you need broadcasting
broker = ListQueueBroker(
    url="redis://localhost:6379",
    result_backend=asyncpg_result_backend,
)


@broker.task
async def best_task_ever() -> None:
    """Solve all problems in the world."""
    await asyncio.sleep(5.5)
    print("All problems are solved!")


async def main():
    await broker.startup()
    task = await best_task_ever.kiq()
    print(await task.wait_result())
    await broker.shutdown()


if __name__ == "__main__":
    asyncio.run(main())
```

## AsyncpgResultBackend configuration
- `dsn`: connection string to PostgreSQL.
- `keep_results`: flag to not remove results from Redis after reading.
- `table_name`: name of the table in PostgreSQL to store TaskIQ results.
- `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.
- `serializer`: type of `TaskiqAsyncpgSerializer` default is `PickleSerializer`
- `**connect_kwargs`: additional connection parameters, you can read more about it in [Asyncpg](https://github.com/qaspen-python/asyncpg) repository.
