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_lockinto INSTALLED_APPS. - Insert
django.contrib.humanizeinto 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.
Metadata
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)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django-db-lock-0.3.0.tar.gz | 8.3 kB | Without provenance | 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
|
Security for django-db-lock 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.