Skip to main content

Lock something and keep status in database.

Project description

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.

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.3.0.tar.gz (8.3 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: django-db-lock-0.3.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for django-db-lock-0.3.0.tar.gz
Algorithm Hash digest
SHA256 cb08e320d294ea2d1d39c0c0573e328de5c7f2e3751e68ac341c0202eab557e8
MD5 b73647091049442411b2bf28a56b1d1e
BLAKE2b-256 d36afeb94f12802e9c7e7f142bd85cd936a8b83c149e0cfa0c3d0c578a670a34

See more details on using hashes here.

Supported by

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