Skip to main content

Database locking

Project description

https://coveralls.io/repos/github/vikingco/django-db-locking/badge.svg?branch=master https://travis-ci.org/vikingco/django-db-locking.svg?branch=master

Usage

The simplest use is by using it as a context manager:

with NonBlockingLock.objects.acquire_lock(obj=model_obj):
    model_obj.do_something()

Or you can keep track of the lock yourself:

try:
    lock = NonBlockingLock.objects.acquire_lock(obj=model_obj)
except AlreadyLocked:
    return False

model_obj.do_something()
lock.release()

If you have no Django model, or you want to be able to specify the lock name yourself, you can do that too:

# this will raise AlreadyLocked, if it's locked
lock = NonBlockingLock.objects.acquire_lock(lock_name='my_lock')
do_something()
lock.release()

Note that locks can expire automatically. There is a LOCK_MAX_AGE settings where you can specify a default lock release value for locks in your entire Django codebase. This value can be overridden per lock by setting the max_age parameter.

Test

You can run the tests with

tox

Releases

v2.0.0:

Merging of master and pre-django-1.8 branches Removes management command in favor of a celery task

v1.2.1:

Fix problem in migration to UUIDField for PostGres

v1.2.0:

Move id to UUIDField, add code quality checks and CI

v1.1.0:

Rename model to NonBlockingLock and add additional features

v1.0.1:

Corrected tests and code clean-up

v1.0.0:

Intial release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-db-locking-2.0.4.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

django_db_locking-2.0.4-py2.py3-none-any.whl (18.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-db-locking-2.0.4.tar.gz.

File metadata

File hashes

Hashes for django-db-locking-2.0.4.tar.gz
Algorithm Hash digest
SHA256 e328ca3bc8ea79e42a7c235775c85de82f65a2ac8a16bc81190799369e4fd92f
MD5 cd04f079fda7ddd19b953b25e4e2d2be
BLAKE2b-256 32ff96980fd817f939575c60a9cfed3f24931e1632005e204a2f488c96f940aa

See more details on using hashes here.

File details

Details for the file django_db_locking-2.0.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_db_locking-2.0.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 7d6759624c368c634fa2e345b620911765ee606ea2bce8528db66a995165add9
MD5 33d22e08c637a5293a052251a2142465
BLAKE2b-256 81d2a3550e9fa07aae3741a96f9fb844dadc72f6d551bddb8bedce913a3110e5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page