MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / acquire_task_lock

Function acquire_task_lock

core/utils.py:292–303  ·  view source on GitHub ↗

Acquire a lock to prevent concurrent task execution.

(task_name, id)

Source from the content-addressed store, hash-verified

290 return cls._pubsub_client
291
292def acquire_task_lock(task_name, id):
293 """Acquire a lock to prevent concurrent task execution."""
294 redis_client = RedisClient.get_client()
295 lock_id = f"task_lock_{task_name}_{id}"
296
297 # Use the Redis SET command with NX (only set if not exists) and EX (set expiration)
298 lock_acquired = redis_client.set(lock_id, "locked", ex=300, nx=True)
299
300 if not lock_acquired:
301 logger.warning(f"Lock for {task_name} and id={id} already acquired. Task will not proceed.")
302
303 return lock_acquired
304
305def release_task_lock(task_name, id):
306 """Release the lock after task execution."""

Callers 12

rehash_streamsFunction · 0.90
refresh_m3u_groupsFunction · 0.90
refresh_account_infoFunction · 0.90
repack_groupMethod · 0.90
refresh_epg_dataFunction · 0.90
fetch_sd_guide_for_epgFunction · 0.90

Calls 2

get_clientMethod · 0.80
setMethod · 0.45