Metadata-Version: 2.5
Name: asyncpg-lock
Version: 0.0.3
Summary: Run long-running work exclusively using PostgreSQL advisory locks
Project-URL: Homepage, https://github.com/Pliner/asyncpg-lock
Author-email: Iurii Pliner <yury.pliner@gmail.com>
License: MIT
License-File: LICENSE
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: asyncpg>=0.30.0
Provides-Extra: dev
Requires-Dist: asyncpg==0.31.0; extra == 'dev'
Requires-Dist: pyright==1.1.407; extra == 'dev'
Requires-Dist: pytest-asyncio==1.4.0; extra == 'dev'
Requires-Dist: pytest-pg==0.0.30; extra == 'dev'
Requires-Dist: pytest==9.0.2; extra == 'dev'
Requires-Dist: ruff==0.14.10; extra == 'dev'
Description-Content-Type: text/markdown

# asyncpg-lock

Run long-running work exclusively using PostgreSQL advisory locks.

## Usage

```python
import asyncio
import asyncpg
import asyncpg_lock


async def worker_func() -> None:
    # something very long-running
    while True:
        await asyncio.sleep(100500)


async def main():
    guard = asyncpg_lock.AdvisoryLockGuard(
        connect=lambda: asyncpg.connect("postgresql://localhost/db")
    )
    # worker_func will not be executed concurrently
    key = 100500
    tasks = [
        asyncio.create_task(guard.run(key, worker_func)),
        asyncio.create_task(guard.run(key, worker_func)),
        asyncio.create_task(guard.run(key, worker_func)),
        asyncio.create_task(guard.run(key, worker_func))
    ]
    await asyncio.gather(*tasks)


asyncio.run(main())
```
