Exemplo n.º 1
0
    def enqueue_worker():
        """A worker to enqueue matches"""
        while not manager.is_complete():
            # try to get next match to queue, error if there is none
            try:
                match = ready.get(timeout=TOURNAMENT_WORKER_TIMEOUT)
            except queue.Empty:
                logging.info('Found no match ready to queue')
                continue


            with manager.lock:
                manager.external_ids[match.internal_id] = [None]
                manager.replays[match.internal_id] = [None]
            while True:
                try:
                    logging.info('Sending match: map={} | {}'.format(None, match))
                    manager.external_ids[match.internal_id] = util.enqueue({
                        'type': 'tour_scrimmage',
                        'tournament_id': tournament_id,
                        'player1': match.player1_pk, # player 1 is always white
                        'player2': match.player2_pk
                    })
                    assert (manager.external_ids[match.internal_id] != None)
                except:
                    logging.error('Error enqueueing match from server: map={} | {}'.format(None, match))
                    time.sleep(TOURNAMENT_WORKER_TIMEOUT)
                else:
                    break
            # tell other thread to wait for results on this game
            monitor.put(match)
 def enqueue_worker():
     """A worker to enqueue matches"""
     while not manager.is_complete():
         try:
             match = ready.get(timeout=TOURNAMENT_WORKER_TIMEOUT)
         except queue.Empty:
             logging.info('Found no match ready to queue')
             continue
         with manager.lock:
             manager.external_ids[match.internal_id] = [None] * len(maps[match.round_name])
             manager.replays[match.internal_id] = [None] * len(maps[match.round_name])
         for index, one_map in enumerate(maps[match.round_name]):
             while True:
                 try:
                     logging.info('Sending match: map={} | {}'.format(one_map, match))
                     manager.external_ids[match.internal_id][index] = util.enqueue({
                         'type': 'tour_scrimmage',
                         'tournament_id': tournament_id,
                         'player1': match.player1_pk if index % 2 == 0 else match.player2_pk,
                         'player2': match.player2_pk if index % 2 == 0 else match.player1_pk,
                         'map_ids': one_map
                     })
                     assert (manager.external_ids[match.internal_id][index] != None)
                 except:
                     logging.error('Error enqueueing match: map={} | {}'.format(one_map, match))
                     time.sleep(TOURNAMENT_WORKER_TIMEOUT)
                 else:
                     break
         monitor.put(match)
Exemplo n.º 3
0
def worker():
    while True:
        scrim = scrim_queue.get()
        logging.info('Enqueueing scrimmage: {}'.format(scrim))
        result = util.enqueue({
            'type': 'scrimmage',
            'player1': scrim['player1'],
            'player2': scrim['player2']
        })
        if result == None:
            scrim_queue.put(scrim)
Exemplo n.º 4
0
 def test_enqueue(self):
     a = []
     util.enqueue(a, 1)
     self.assertEqual(a, [1])