def get_locked_tasks_project(project_id): """Returns a list of locked tasks for a given project.""" tasks = [] redis_conn = sentinel.master # Get the active users key for this project. key = get_active_user_key(project_id) # Get the users for each locked task. for user_key in redis_conn.hgetall(key).iteritems(): user_id = user_key[0] # Get locks by user. user_tasks = get_user_tasks(user_id, TIMEOUT) # Get task ids for the locks. user_task_ids = user_tasks.keys() # Get project ids for the task ids. results = get_task_ids_project_id(user_task_ids) # For each locked task, check if the lock is still active. for task_id, task_project_id in zip(user_task_ids, results): # Match the requested project id. if int(task_project_id) == project_id: # Calculate seconds remaining. seconds_remaining = LockManager.seconds_remaining(user_tasks[task_id]) if seconds_remaining > 0: # This lock has not yet expired. tasks.append({ "user_id": user_id, "task_id": task_id, "seconds_remaining": seconds_remaining }) return tasks
def get_task_id_and_duration_for_project_user(project_id, user_id): user_tasks = get_user_tasks(user_id, TIMEOUT) user_task_ids = user_tasks.keys() results = get_task_ids_project_id(user_task_ids) max_seconds_task_id = -1 max_seconds_remaining = float('-inf') for task_id, task_project_id in zip(user_task_ids, results): if not task_project_id: task_project_id = task_repo.get_task(task_id).project_id save_task_id_project_id(task_id, task_project_id, 2 * TIMEOUT) if int(task_project_id) == project_id: seconds_remaining = LockManager.seconds_remaining( user_tasks[task_id]) if seconds_remaining > max_seconds_remaining: max_seconds_task_id = int(task_id) max_seconds_remaining = seconds_remaining if max_seconds_task_id > 0: return max_seconds_task_id, max_seconds_remaining return None, -1