def update_task_status( task_id: int, team_id: int, current_round: int, checker_verdict: models.CheckerVerdict, ) -> None: """ Update task status in database. :param task_id: :param team_id: :param current_round: :param checker_verdict: instance of CheckerActionResult """ add = 0 public = checker_verdict.public_message if checker_verdict.status == TaskStatus.UP: add = 1 if checker_verdict.action == Action.PUT: public = 'OK' params = { 'round': current_round, 'task_id': task_id, 'team_id': team_id, 'status': checker_verdict.status.value, 'public_message': public, 'private_message': checker_verdict.private_message, 'command': checker_verdict.command, 'passed': add, } with storage.utils.db_cursor(dict_cursor=True) as (conn, curs): curs.execute(_INSERT_TEAMTASKS_TO_LOG_QUERY, params) curs.execute(_UPDATE_TEAMTASKS_QUERY, params) data = curs.fetchone() conn.commit() data['round'] = current_round with storage.utils.redis_pipeline(transaction=True) as pipe: pipe.xadd( CacheKeys.teamtasks(team_id, task_id), dict(data), maxlen=50, approximate=False, ).execute()
def get_teamtasks_for_team(team_id: int) -> List[dict]: """Fetch teamtasks for team for all tasks.""" tasks = storage.tasks.get_tasks() with storage.utils.redis_pipeline(transaction=False) as pipe: for task in tasks: pipe.xrevrange(CacheKeys.teamtasks(team_id, task.id)) data = pipe.execute() data = sum(data, []) results = [] for timestamp, record in data: record['timestamp'] = timestamp results.append(record) return results
def get_last_teamtasks() -> List[dict]: """Fetch team tasks, last for each team for each task.""" teams = storage.teams.get_teams() tasks = storage.tasks.get_tasks() with storage.utils.redis_pipeline(transaction=True) as pipe: for team in teams: for task in tasks: pipe.xrevrange(CacheKeys.teamtasks(team.id, task.id), count=1) data = pipe.execute() data = sum(data, []) results = [] for timestamp, record in data: record['timestamp'] = timestamp results.append(record) results = process_teamtasks(results) return results