Skip to main content

Lock something and keep status in database.

Project description

Lock something and keep status in database.

Install

pip install django-db-lock

Settings

INSTALLED_APPS = [
    ...
    'django_db_lock',
    ...
]

Use inside project

import uuid
from django_db_lock import acquire_lock
from django_db_lock import release_lock

def view01(request):
    lock_name = "view01lock"
    worker_name = str(uuid.uuid4())
    timeout = 10
    locked = acquire_lock(lock_name, worker_name, timeout)
    if locked:
        try:
            ....
        finally:
            release_lock(lock_name, worker_name)
    ...

Use outout project

import requests

def view02(request):
    data = {
        "lock_name": "view02lock",
        "worker_name": str(uuid.uuid4()),
        "timeout": 10,
    }
    response = request.post("http://api.server/system/dblock/acquire-lock", data=data)
    if response["result"]:
        try:
            ....
        finally:
            request.post("http://api.server/system/dblock/acquire-lock", data=data)
    ...

Install LockAdmin in admin site

Add REGISTER_DJANGO_DB_LOCK_ADMIN = True in settings.py will register LockAdmin in django’s default admin site.

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-lock-0.1.0.tar.gz (5.4 kB view details)

Uploaded Source

File details

Details for the file django-db-lock-0.1.0.tar.gz.

File metadata

File hashes

Hashes for django-db-lock-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cf75a2fdccf16fc246e0e81cbf5a9a1ba353aa428343f3f59b9d24ba8f257a00
MD5 2d26fa14cae1511314b1ddb747ff15d4
BLAKE2b-256 2a345c0acce3f1945f09862120e962fd2ee9ede0b3d8a7808e70473a467ba6d6

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