Name | django-db-lock JSON |
Version |
0.6.3
JSON |
| download |
home_page | |
Summary | Lock something and keep status in database. A simple distributed lock system. |
upload_time | 2023-09-14 12:36:26 |
maintainer | Chao WeiZhi |
docs_url | None |
author | Chao WeiZhi |
requires_python | |
license | MIT |
keywords |
django extentions
django db lock
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# django-db-lock
Lock something and keep status in database. A simple distributed lock system.
## Install
```shell
pip install django-db-lock
```
## Usage With django_db_lock app in project
**pro/settings.py**
```
INSTALLED_APPS = [
...
'django_db_lock',
'django.contrib.humanize',
...
]
DJANGO_DB_LOCK_AUTO_REGISTER_MODEL = True
DJANGO_DB_LOCK_AUTO_REGISTER_ADMIN = True
DJANGO_DB_LOCK_AUTO_REGISTER_SERVICES = 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_MODEL default to True, so that the Lock model is auto registerd.
- DJANGO_DB_LOCK_AUTO_REGISTER_ADMIN default to True, so that the Lock model's admin site is auto registered.
- DJANGO_DB_LOCK_AUTO_REGISTER_SERVICES default to True, so that the Lock Services is auto registered in django_db_lock.urls.
- 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('dblock/', include("django_db_lock.urls")),
...
]
```
- Optional.
- Export db-lock services only if you have client app to use the service.
**app/views.py**
```
import uuid
from django_db_lock.client import get_default_lock_server
from django_db_lock.client import DjangoDbLock
def view01(request):
lock_server = get_default_lock_server()
lock_name = "view01lock"
worker_name = "view01worker"
timeout = 10
with DjangoDbLock(lock_server, lock_name, worker_name, timeout) as locked:
if locked:
do_something...
...
```
## Usage Without django_db_lock app in project
**pro/settings.py**
```
DJANGO_DB_LOCK_AUTO_REGISTER_MODEL = False
DJANGO_DB_LOCK_AUTO_REGISTER_ADMIN = False
DJANGO_DB_LOCK_AUTO_REGISTER_SERVICES = False
DJANGO_DB_LOCK_API_SERVER = **You api server**
DJANGO_DB_LOCK_ACQUIRE_LOCK_PATH = "acquireLock"
DJANGO_DB_LOCK_RELEASE_LOCK_PATH = "releaseLock"
```
- You must set DJANGO_DB_LOCK_AUTO_REGISTER_MODEL to False, so that you will not get django_db_model's Lock model auto registered.
- You must set DJANGO_DB_LOCK_API_SERVER in your settings.py
- DJANGO_DB_LOCK_ACQUIRE_LOCK_PATH default to "acquireLock". Only if your server have changed the url, you have to change it to match the server.
- DJANGO_DB_LOCK_RELEASE_LOCK_PATH default to "releaseLock". Only if your server have changed the url, you have to change it to match the server.
**app/views.py**
```
import uuid
from django_db_lock.client import get_default_lock_server
from django_db_lock.client import DjangoDbLock
def view01(request):
lock_server = get_default_lock_server()
lock_name = "view01lock"
worker_name = str(uuid.uuid4()) # unique worker name
timeout = 10 # the lock will be released by force after `timeout` seconds.
with DjangoDbLock(lock_server, lock_name, worker_name=worker_name, timeout=timeout) as locked:
if locked:
do_something...
...
```
## Releases
### v0.1.0
- First release.
### v0.1.1
- Fix something.
### v0.2.0
- 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.
- Note: Incompatible with old releases.
### v0.2.1
- Fix setup description.
### v0.3.0
- Add django_db_lock.client.DjangoDbLock.
### v0.3.1
- Rename zh_hans to zh_Hans.
- Fix setup descriptions.
### v0.4.0
- Add abstract LockBase model.
- Add django_db_lock.client module.
- Put services in one class, so that you may create many lock server instance.
### v0.4.1
- Add setup requires library.
### v0.5.1
- Use redis lock before db lock.
### v0.5.2
- Release redis lock if lock in redis success but lock in database fail.
- Fix problems, and unit tests passed.
### v0.5.3
- Fix get_redis_connection problem.
### v0.5.4
- Force worker name and lock name to str type.
### v0.5.5
- Add debug info.
### v0.6.3
- By default, don't save lock status in database.
Raw data
{
"_id": null,
"home_page": "",
"name": "django-db-lock",
"maintainer": "Chao WeiZhi",
"docs_url": null,
"requires_python": "",
"maintainer_email": "chaoweizhi@zencore.cn",
"keywords": "django extentions,django db lock",
"author": "Chao WeiZhi",
"author_email": "chaoweizhi@zencore.cn",
"download_url": "https://files.pythonhosted.org/packages/e4/54/a83585536f801ffbb028edf00a5d5f3fc19d88ca6b8a704b363bb313cae5/django-db-lock-0.6.3.tar.gz",
"platform": null,
"description": "# django-db-lock\n\nLock something and keep status in database. A simple distributed lock system.\n\n## Install\n\n```shell\npip install django-db-lock\n```\n\n## Usage With django_db_lock app in project\n\n**pro/settings.py**\n\n```\nINSTALLED_APPS = [\n ...\n 'django_db_lock',\n 'django.contrib.humanize',\n ...\n]\n\nDJANGO_DB_LOCK_AUTO_REGISTER_MODEL = True\nDJANGO_DB_LOCK_AUTO_REGISTER_ADMIN = True\nDJANGO_DB_LOCK_AUTO_REGISTER_SERVICES = True\nDJANGO_DB_LOCK_APP_LABEL = \"django_db_lock\"\n```\n\n- Required.\n- Insert `django_db_lock` into INSTALLED_APPS.\n- Insert `django.contrib.humanize` into INSTALLED_APPS to enable the i18n translation.\n- DJANGO_DB_LOCK_AUTO_REGISTER_MODEL default to True, so that the Lock model is auto registerd.\n- DJANGO_DB_LOCK_AUTO_REGISTER_ADMIN default to True, so that the Lock model's admin site is auto registered.\n- DJANGO_DB_LOCK_AUTO_REGISTER_SERVICES default to True, so that the Lock Services is auto registered in django_db_lock.urls.\n- 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.\n\n**pro/urls.py**\n\n```\n...\nfrom django.urls import path\nfrom django.urls import include\n\nurlpatterns = [\n ...\n path('dblock/', include(\"django_db_lock.urls\")),\n ...\n]\n```\n\n- Optional.\n- Export db-lock services only if you have client app to use the service.\n\n**app/views.py**\n\n```\nimport uuid\nfrom django_db_lock.client import get_default_lock_server\nfrom django_db_lock.client import DjangoDbLock\n\ndef view01(request):\n lock_server = get_default_lock_server()\n lock_name = \"view01lock\"\n worker_name = \"view01worker\"\n timeout = 10\n with DjangoDbLock(lock_server, lock_name, worker_name, timeout) as locked:\n if locked:\n do_something...\n ...\n```\n\n## Usage Without django_db_lock app in project \n\n**pro/settings.py**\n\n```\nDJANGO_DB_LOCK_AUTO_REGISTER_MODEL = False\nDJANGO_DB_LOCK_AUTO_REGISTER_ADMIN = False\nDJANGO_DB_LOCK_AUTO_REGISTER_SERVICES = False\nDJANGO_DB_LOCK_API_SERVER = **You api server**\nDJANGO_DB_LOCK_ACQUIRE_LOCK_PATH = \"acquireLock\"\nDJANGO_DB_LOCK_RELEASE_LOCK_PATH = \"releaseLock\"\n\n```\n\n- You must set DJANGO_DB_LOCK_AUTO_REGISTER_MODEL to False, so that you will not get django_db_model's Lock model auto registered.\n- You must set DJANGO_DB_LOCK_API_SERVER in your settings.py\n- DJANGO_DB_LOCK_ACQUIRE_LOCK_PATH default to \"acquireLock\". Only if your server have changed the url, you have to change it to match the server.\n- DJANGO_DB_LOCK_RELEASE_LOCK_PATH default to \"releaseLock\". Only if your server have changed the url, you have to change it to match the server.\n\n**app/views.py**\n\n```\nimport uuid\nfrom django_db_lock.client import get_default_lock_server\nfrom django_db_lock.client import DjangoDbLock\n\ndef view01(request):\n lock_server = get_default_lock_server()\n lock_name = \"view01lock\"\n worker_name = str(uuid.uuid4()) # unique worker name\n timeout = 10 # the lock will be released by force after `timeout` seconds.\n with DjangoDbLock(lock_server, lock_name, worker_name=worker_name, timeout=timeout) as locked:\n if locked:\n do_something...\n ...\n```\n\n\n## Releases\n\n### v0.1.0\n\n- First release.\n\n### v0.1.1\n\n- Fix something.\n\n### v0.2.0\n\n- Reconstituted.\n- Allow register the Lock model into another app, use setting DJANGO_DB_LOCK_APP_LABEL.\n- Use django-apiview to provides restful API.\n- Use camelStyle parameter format.\n- Add i18n for zh-hans.\n- Note: Incompatible with old releases.\n\n### v0.2.1\n\n- Fix setup description.\n\n### v0.3.0\n\n- Add django_db_lock.client.DjangoDbLock.\n\n### v0.3.1\n\n- Rename zh_hans to zh_Hans.\n- Fix setup descriptions. \n\n### v0.4.0\n\n- Add abstract LockBase model.\n- Add django_db_lock.client module.\n- Put services in one class, so that you may create many lock server instance.\n\n### v0.4.1\n\n- Add setup requires library.\n\n### v0.5.1\n\n- Use redis lock before db lock.\n\n### v0.5.2\n\n- Release redis lock if lock in redis success but lock in database fail.\n- Fix problems, and unit tests passed.\n\n### v0.5.3\n\n- Fix get_redis_connection problem.\n\n### v0.5.4\n\n- Force worker name and lock name to str type.\n\n### v0.5.5\n\n- Add debug info.\n\n### v0.6.3\n\n- By default, don't save lock status in database.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Lock something and keep status in database. A simple distributed lock system.",
"version": "0.6.3",
"project_urls": null,
"split_keywords": [
"django extentions",
"django db lock"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7aa02934407ab98e72cbb3389ed4b1208de5e70648366c79d6cc4117b89d0e2d",
"md5": "a71265e679290378a27f4147362c1eeb",
"sha256": "18de50b03531fbe97ff91e9e34f4b600391941b47b32122efc43968c7f404351"
},
"downloads": -1,
"filename": "django_db_lock-0.6.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a71265e679290378a27f4147362c1eeb",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 11793,
"upload_time": "2023-09-14T12:36:24",
"upload_time_iso_8601": "2023-09-14T12:36:24.379137Z",
"url": "https://files.pythonhosted.org/packages/7a/a0/2934407ab98e72cbb3389ed4b1208de5e70648366c79d6cc4117b89d0e2d/django_db_lock-0.6.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e454a83585536f801ffbb028edf00a5d5f3fc19d88ca6b8a704b363bb313cae5",
"md5": "6e913d6b7acd2c4cba2a7b6579279a9f",
"sha256": "8b64ae196da223039f2901f63a2bea5d13d35dc126e9f67f38a44862a87c4155"
},
"downloads": -1,
"filename": "django-db-lock-0.6.3.tar.gz",
"has_sig": false,
"md5_digest": "6e913d6b7acd2c4cba2a7b6579279a9f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 10305,
"upload_time": "2023-09-14T12:36:26",
"upload_time_iso_8601": "2023-09-14T12:36:26.607307Z",
"url": "https://files.pythonhosted.org/packages/e4/54/a83585536f801ffbb028edf00a5d5f3fc19d88ca6b8a704b363bb313cae5/django-db-lock-0.6.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-14 12:36:26",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "django-db-lock"
}