def wait_for_fleet_to_be_active()

in production-deployment-sample-script/utils/utilities.py [0:0]


def wait_for_fleet_to_be_active(game_lift_client: GameLiftClient, _fleet_id: str):
    new_fleet_state = 'NEW'
    print('Sleeping and describing Fleet %s...' % _fleet_id)
    while new_fleet_state != 'ACTIVE' and new_fleet_state != 'ERROR':
        time.sleep(FLEET_SLEEP)
        describe_fleet_response = game_lift_client.describe_fleet_attributes(_fleet_id)
        new_fleet_state = describe_fleet_response['FleetAttributes'][0]['Status']
        print("%s: Fleet %s is still pending in status %s..." % (datetime.now(), _fleet_id, new_fleet_state))
    # If the fleet ended in ERROR, throw an exception and exit
    if new_fleet_state == 'ERROR':
        raise Exception("Fleet %s went into ERROR, exiting." % _fleet_id)
    # Check for Fleet locations and ensure those also go ACTIVE before continuing
    locations_response = game_lift_client.describe_fleet_location_attributes(_fleet_id, None)
    locations_remaining = [item.get('LocationState').get('Location') for item in locations_response['LocationAttributes']]
    while len(locations_remaining) != 0:
        time.sleep(FLEET_SLEEP)
        locations_response = game_lift_client.describe_fleet_location_attributes(_fleet_id, locations_remaining)
        print("%s: Waiting on locations %s to go ACTIVE: %s" %
              (datetime.now(), locations_remaining, locations_response['LocationAttributes']))
        for location in locations_response['LocationAttributes']:
            if location['LocationState']['Status'] == 'ACTIVE':
                locations_remaining.remove(location['LocationState']['Location'])