set_lock¶
The set_lock
management command allows you to create / renew locks using django-lockmgr from the command line.
If you don’t specify any behaviour switches such as --no-renew
or --fail
, then set_lock will create any
locks which aren’t already locked, and renew any locks which are already locked.
Below is an excerpt from ./manage.py set_lock --help
(added at 21 Nov @ 9 PM UTC):
-h, --help show this help message and exit
-n, --no-renew Do not renew any locks which already exist
-r, --only-renew Only renew existing locks, do not create new ones.
-k, --no-timeout Never expire these locks (--timeout will be ignored). They must be manually unlocked.
-t TIMEOUT, --timeout TIMEOUT Lock timeout in seconds (default 600)
-e, --fail Return an error (exit code 2) if one or more locks already exist. (will not create/renew ANY
passed locks if one of the passed lock names exists)
The -e
or --fail
option can be a useful option when you’re wanting to set multiple locks in unison, but
you need to be sure that all of the locks are set at the same time - and if any of the locks already exist, any
of the locks specified should not be created / be rolled back.
Below is an example of this special feature in use:
user@host ~ $ ./manage.py set_lock example
> Lock example did not yet exist. Successfully locked 'example' - expiry: 2019-11-21 15:30:03.857412
user@host ~ $ ./manage.py set_lock -e hello world example
> Lock hello did not yet exist. Successfully locked 'hello' - expiry: 2019-11-21 15:30:27.706378
> Lock world did not yet exist. Successfully locked 'world' - expiry: 2019-11-21 15:30:27.709321
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!! An existing lock was found:
!!! <Lock name='example' locked_by='Chriss-iMac-Pro.local' locked_until='2019-11-21 15:30:03.857412'>
!!! As you have specified -e / --fail, any locks created during this session will now be
!!! rolled back for your safety.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!! Any locks created during this session should now have been removed.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
user@host ~ $ ./manage.py list_locks
There are currently 1 active locks using Privex Django-LockMgr
=========================================================
<Lock name='example' locked_by='example.org' lock_process='None' locked_until='2019-11-21 15:30:03.857412'>
=========================================================
Classes
|