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.1 2020/09/01
- Rename zh_hans to zh_Hans.
- Fix setup descriptions.
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
Release history Release notifications | RSS feed
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.1.tar.gz
(8.4 kB
view details)
File details
Details for the file django-db-lock-0.3.1.tar.gz
.
File metadata
- Download URL: django-db-lock-0.3.1.tar.gz
- Upload date:
- Size: 8.4 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45a00f73a6e0a915be8608f47330ba9c72b216c3945d1eaa41a0a1686935cdc3 |
|
MD5 | 4cb82898b61be453a117cb16f11e4eb2 |
|
BLAKE2b-256 | e9161cff1a44624520c327cba1db28b73e330631603ddb1a631f8dba5fc6e907 |