Skip to content

IVS-876 - Django Management Command to display Redis Locks#301

Merged
rw-bsi merged 1 commit into
developmentfrom
IVS-876_Django_Mgmt_Command_for_Redis_locks
Jun 8, 2026
Merged

IVS-876 - Django Management Command to display Redis Locks#301
rw-bsi merged 1 commit into
developmentfrom
IVS-876_Django_Mgmt_Command_for_Redis_locks

Conversation

@rw-bsi

@rw-bsi rw-bsi commented Jun 6, 2026

Copy link
Copy Markdown
Contributor
  • Django Management command display_user_locks
  • Unit tests

Example:

(venv) user:~/Projects/bsi/validate/backend (development) $ python3 manage.py display_user_locks
2026-06-06 15:17:24,821 [INFO] m:display_user_locks pid:20485 tid:8385863296 -- Found 1 active user locks:
2026-06-06 15:17:24,821 [INFO] m:display_user_locks pid:20485 tid:8385863296 -- - User ID: 3, Task: apps.ifc_validation.tasks.normative_ia_subtask, TTL: 3,198 seconds

(venv) user:~/Projects/bsi/validate/backend (development) $ python3 manage.py display_user_locks
2026-06-06 15:19:46,839 [INFO] m:display_user_locks pid:21273 tid:8385863296 -- No active user locks found.

@rw-bsi rw-bsi self-assigned this Jun 6, 2026
@rw-bsi rw-bsi requested review from Ghesselink, aothms and civilx64 June 6, 2026 15:45
@rw-bsi rw-bsi marked this pull request as ready for review June 6, 2026 15:46
def handle(self, *args, **options):

# Scan for keys matching the lock pattern
lock_pattern = "lock:celery:user:*:task:*"

@aothms aothms Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried for a second or so to make this a bit more declarative like but I guess it's not worth it until we have a lot more of these patterns:

@dataclass
class placeholder:
  name: str
  def to_glob(self): return '*'
  def to_re(self): return r'(?P<{self.name}>[^:]+)'

@dataclass
class query:
  items : list
  def to_glob(self): return ':'.join(i.to_glob() for i in self.items if not isinstance(i, str) else i)
  def to_re(self): return re.compile(':'.join(i.to_re() for i in self.items if not isinstance(i, str) else i))

q = query(['lock', 'celery', 'user', placeholder('user_id'), 'task', palceholder('task_name')])

redis_client.keys(q.to_glob())

...

user_id, task_name = q.to_re().match(key).group('user_id', 'task_name')

...

@rw-bsi rw-bsi merged commit 8911081 into development Jun 8, 2026
2 of 3 checks passed
@rw-bsi rw-bsi deleted the IVS-876_Django_Mgmt_Command_for_Redis_locks branch June 8, 2026 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants