def acquire_lock(task_id, user_id, limit, timeout, pipeline=None, execute=True): redis_conn = sentinel.master pipeline = pipeline or redis_conn.pipeline(transaction=True) lock_manager = LockManager(redis_conn, timeout) task_users_key = get_task_users_key(task_id) user_tasks_key = get_user_tasks_key(user_id) if lock_manager.acquire_lock(task_users_key, user_id, limit, pipeline=pipeline): lock_manager.acquire_lock(user_tasks_key, task_id, float('inf'), pipeline=pipeline) if execute: return all(not isinstance(r, Exception) for r in pipeline.execute()) return True return False
def acquire_lock(project_id, task_id, user_id, limit, timeout): lock_manager = LockManager(sentinel.master, timeout) key = get_key(project_id, task_id) return lock_manager.acquire_lock(key, user_id, limit)