Skip to content

Commit 6a402a9

Browse files
committed
Add some docs
1 parent d32e032 commit 6a402a9

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

docs/lib/advisory_lock.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,40 @@ is the choice of the programmer in the specific case.
3333
In this case, the `return` would be okay in the situation where `my_task` is idempotent,
3434
and there is a "fallback" schedule in case a call was missed.
3535
The blocking/non-blocking choices are very dependent on the specific design and situation.
36+
37+
## Debugging Advisory Locks
38+
39+
For debugging purposes, several utility functions are available to inspect active advisory locks:
40+
41+
### Get Active Advisory Locks
42+
43+
```python
44+
from ansible_base.lib.utils.db import get_active_advisory_locks
45+
46+
# Get all active advisory locks
47+
active_locks = get_active_advisory_locks()
48+
for lock in active_locks:
49+
print(f"Lock ID: {lock['objid']}, PID: {lock['pid']}")
50+
```
51+
52+
### Convert String to Lock ID
53+
54+
```python
55+
from ansible_base.lib.utils.db import string_to_advisory_lock_id
56+
57+
# Convert a string to the corresponding advisory lock ID
58+
lock_id = string_to_advisory_lock_id('my_task_lock')
59+
print(f"Lock ID for 'my_task_lock': {lock_id}")
60+
```
61+
62+
### Convert Lock ID to Debug Info
63+
64+
```python
65+
from ansible_base.lib.utils.db import advisory_lock_id_to_debug_info
66+
67+
# Get debug information for a specific lock ID
68+
debug_info = advisory_lock_id_to_debug_info(lock_id)
69+
print(f"Original string: {debug_info}")
70+
```
71+
72+
These debugging utilities are particularly useful when troubleshooting stuck locks or understanding which processes are holding specific advisory locks in a PostgreSQL database.

0 commit comments

Comments
 (0)