Metadata-Version: 2.4
Name: django-postgres-lock
Version: 0.2
Summary: Django Postgres Lock
Maintainer-email: The Developer Society <studio@dev.ngo>
License-Expression: BSD-3-Clause
Project-URL: Homepage, https://github.com/developersociety/django-postgres-lock
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 3.2
Classifier: Framework :: Django :: 4.2
Classifier: Framework :: Django :: 5.2
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: Django>=3.2
Dynamic: license-file

# Django Postgres Lock

A [Django](https://www.djangoproject.com/) management command which will run a command inside a
Postgres lock, ensuring that only a single instance of the inner command will run.

## Installation

Using [pip](https://pip.pypa.io/):

```console
$ pip install django-postgres-lock
```

Edit your Django project's settings module, and add the application to ``INSTALLED_APPS``:

```python
INSTALLED_APPS = [
    # ...
    "postgres_lock",
    # ...
]
```

## Usage

To run clearsessions with the default lock:

```console
$ ./manage.py command_lock -- ./manage.py clearsessions
```

To use a unique lock for this task:

```console
$ ./manage.py command_lock --name clearsessions -- ./manage.py clearsessions
```

To exit immediately if a lock can't be acquired:

```console
$ ./manage.py command_lock --try --name clearsessions -- ./manage.py clearsessions
```

To ignore a lock failure and return a successful exit code:

```console
$ ./manage.py command_lock --try --ignore-fail --name clearsessions -- ./manage.py clearsessions
```
