This package provides decorators that will try to acquire redis lock before calling decorated function.
Installation
pip install dumblock
Usage
Set DUMBLOCK_REDIS_URL in your django settings:
DUMBLOCK_REDIS_URL = "redis://localhost:6379"
lock_or_exit
Decorator. Before decorated function starts, try to acquire redis lock with specified key. If lock is acquired successfully, proceed executing the function. Otherwise, return immediately. The key argument can contain templated string, wich will be rendered with args and kwargs, passed to the function.
Example:
@lock_or_exit('lock_work_{}')
def workwork(x):
pass
workwork(3) # Will try to acquire redis lock 'lock_work_3'
lock_wait
Decorator. Before decorated function starts, try to acquire redis lock with specified key, waiting for waittime seconds if needed. If lock is acquired successfully, proceed executing the function. Otherwise, raise dumblock.TimeoutError. The key argument can contain templated string, wich will be rendered with args and kwargs, passed to the function.
Example:
@lock_wait('lock_work_{}', waittime=4)
def workwork(x):
pass
workwork(3) # Will try to acquire redis lock 'lock_work_3' for 4 seconds
Metadata
Release files for dumblock 0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dumblock-0.1.tar.gz | 2.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dumblock-0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.6 kB
Release files / dumblock-0.1.tar.gz
| Download URL | dumblock-0.1.tar.gz |
|---|---|
| Size | 2.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1a27af91b55706f54fb26036e058f3fe7fe2be3c7e882964d2ddecf14b09bda4
|
|
BLAKE2b-256 checksum How to use checksums |
30672466e7765750ba1ceae8ad270d9c41f191a36647bc685a4c6934e7d58b29
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / dumblock-0.1-py3-none-any.whl
| Download URL | dumblock-0.1-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
84af2bf28140a42ffbb90fb2d64bbe8010a7c43cddefca6985c57c37facd0000
|
|
BLAKE2b-256 checksum How to use checksums |
29eb63dbd66897fe184f4c83cc4f405b4380b458abe6000f766a8ab05873291d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |