(notif)
Add this notification to the queue. Run battle if it completes a set.
Add this notification to the queue. Run battle if it completes a set.
Add this notification to the queue . Run battle if it completes a set .
def add_server_ready_notif(notif):
    """Add this notification to the queue. Run battle if it completes a set."""
    battle_info = notif['battle_info']
    server_ready_notifs[battle_info].add(notif)
    battle_notifs = server_ready_notifs[battle_info]
    if len(battle_notifs) > 4:
        logging.warn("We have too many battle notifs. How did this happen?")
        logging.warn(", ".join([
            "{}.{}.{}".format(notif['agent_id'], notif['aid'],
                              notif['docker_image']) for notif in battle_notifs
        ]))
    elif len(battle_notifs) == 4:
        # Everyone is ready. Let's do this.
        battle_notifs = sorted(list(battle_notifs), key=lambda k: k['agent_id'])
        agents = {k:v for k, v in battle_notifs \
                  if k in ['aid', 'docker_image', 'agent_id']}
        run_battle(battle_info, agents)
        del server_ready_notifs[battle_info]
def add_server_ready_notif ( notif ) : battle_info = notif [ 'battle_info' ] server_ready_notifs [ battle_info ] . add ( notif ) battle_notifs = server_ready_notifs [ battle_info ] if len ( battle_notifs ) > 4 : logging . warn ( "We have too many battle notifs. How did this happen?" ) logging . warn ( ", " . join ( [ "{}.{}.{}" . format ( notif [ 'agent_id' ] , notif [ 'aid' ] , notif [ 'docker_image' ] ) for notif in battle_notifs ] ) ) elif len ( battle_notifs ) == 4 : # Everyone is ready. Let's do this. battle_notifs = sorted ( list ( battle_notifs ) , key = lambda k : k [ 'agent_id' ] ) agents = { k : v for k , v in battle_notifs if k in [ 'aid' , 'docker_image' , 'agent_id' ] } run_battle ( battle_info , agents ) del server_ready_notifs [ battle_info ]