Skip to main content

django-db-lock

Lock something and keep status in database.

Install

pip install django-db-lock

Usage

pro/settings.py

INSTALLED_APPS = [
    ...
    'django_db_lock',
    'django.contrib.humanize',
    ...
]

DJANGO_DB_LOCK_AUTO_REGISTER_ADMIN = True
DJANGO_DB_LOCK_APP_LABEL = django_db_lock
  • Required.
  • Insert django_db_lock into INSTALLED_APPS.
  • Insert django.contrib.humanize into INSTALLED_APPS to enable the i18n translation.
  • DJANGO_DB_LOCK_AUTO_REGISTER_ADMIN default to True, so that the Lock model's admin site is auto registered.
  • DJANGO_DB_LOCK_APP_LABEL default to django_db_lock, so that the Lock model is registered under django_db_lock. You can change it to any exists app.

pro/urls.py

...
from django.urls import path
from django.urls import include

urlpatterns = [
    ...
    path('system/dblock/', include("django_db_lock.urls")),
    ...
]
  • Optional.
  • Export db-lock services only if you have client programs.

app/views.py

import uuid
from django_db_lock.services import acquire_lock
from django_db_lock.services import release_lock

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

Use it in app without django_db_lock

import requests

def view02(request):
    lock_name = "view02lock"
    worker_name = "view02worker"
    timeout = 10
    response = requests.get("http://api.server/system/dblock/acquireLock", params={"lockName": lock_name, "workerName": worker_name, "timeout": timeout})
    response_data = json.loads(response.content)
    if response_data["result"] == True:
        try:
            ....
        finally:
            requests.get("http://api.server/system/dblock/acquireLock", params={"lockName": lock_name, "workerName": worker_name})
    ...

Releases

v0.3.0 2020/09/01

  • Add django_db_lock.client.DjangoDbLock.

v0.2.1 2020/08/29

  • Fix setup description.

v0.2.0 2020/08/29

  • Reconstituted.
  • Allow register the Lock model into another app, use setting DJANGO_DB_LOCK_APP_LABEL.
  • Use django-apiview to provides restful API.
  • Use camelStyle parameter format.
  • Add i18n for zh-hans.
  • Incompatible with old releases.

v0.1.1 2018/5/11

  • Fix.

v0.1.0 2018/5/10

  • First release.

Release files for django-db-lock 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-db-lock 0.3.0
File Size Uploaded
django-db-lock-0.3.0.tar.gz 8.3 kB Details

Release files / django-db-lock-0.3.0.tar.gz

Download URL django-db-lock-0.3.0.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
cb08e320d294ea2d1d39c0c0573e328de5c7f2e3751e68ac341c0202eab557e8
BLAKE2b-256 checksum
How to use checksums
d36afeb94f12802e9c7e7f142bd85cd936a8b83c149e0cfa0c3d0c578a670a34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.8

Release history Release notifications | RSS feed

0.6.4

2 release files

0.6.3

2 release files

0.5.2

1 release file

0.5.1

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.1

1 release file

This release

0.3.0 This release

1 release file

0.2.1

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page