<commit_before>#!/bin/bash

PEERS=${TMP:-/tmp}/$SERVICE_NAME.json

function getServiceAddressesFromConsul() {
        curl -s http://consul:8500/v1/catalog/service/$SERVICE_NAME?tag=es-transport > $PEERS
}

function getOwnPublishPort() {
        jq -r ".[] | select(.ServiceID==\"$SERVICE_9300_ID\") | .ServicePort" $PEERS
}

function getOwnPublishAddress() {
        jq -r ".[] | select(.ServiceID==\"$SERVICE_9300_ID\") | .Address" $PEERS
}

function getNumberOfPeers() {
        jq -r 'length'  $PEERS
}

function getPeerAddressList() {
        jq -r '[ .[] | [ .Address, .ServicePort | tostring ] | join(":")  ] | join(",")'  $PEERS
}

function waitForAllServers() {
        COUNT=0
        NR_OF_SERVERS=0
        while [ $COUNT -lt 60 -a $NR_OF_SERVERS -lt $TOTAL_NR_OF_SERVERS ] ; do
                getServiceAddressesFromConsul
                NR_OF_SERVERS=$(getNumberOfPeers)
                if [ $NR_OF_SERVERS -lt $TOTAL_NR_OF_SERVERS ] ; then
                        echo "$NR_OF_SERVERS found in registry, $TOTAL_NR_OF_SERVERS required. sleeping 2s." >&2
                        sleep 2
                        COUNT=$(($COUNT + 1))
                fi
        done
        if [ $NR_OF_SERVERS -lt $TOTAL_NR_OF_SERVERS ] ; then
                echo "Failed to acquire the required number of services" >&2
                exit 1
        fi
}<commit_msg>robust handling of 0 servers in registry<commit_after>#!/bin/bash

PEERS=${TMP:-/tmp}/$SERVICE_NAME.json

function getServiceAddressesFromConsul() {
        curl -s http://consul.service.consul:8500/v1/catalog/service/$SERVICE_NAME?tag=es-transport > $PEERS
}

function getOwnPublishPort() {
        jq -r ".[] | select(.ServiceID==\"$SERVICE_9300_ID\") | .ServicePort" $PEERS
}

function getOwnPublishAddress() {
        jq -r ".[] | select(.ServiceID==\"$SERVICE_9300_ID\") | .Address" $PEERS
}

function getNumberOfPeers() {
        RESULT=$(jq -r 'length'  $PEERS)
	if [ -z "$RESULT" ] ; then
		RESULT=0
	fi
	echo $RESULT
}

function getPeerAddressList() {
        jq -r '[ .[] | [ .Address, .ServicePort | tostring ] | join(":")  ] | join(",")'  $PEERS
}

function waitForAllServers() {
        COUNT=0
        NR_OF_SERVERS=0
        while [ $COUNT -lt 60 -a $NR_OF_SERVERS -lt $TOTAL_NR_OF_SERVERS ] ; do
                getServiceAddressesFromConsul
                NR_OF_SERVERS=$(getNumberOfPeers)
                if [ $NR_OF_SERVERS -lt $TOTAL_NR_OF_SERVERS ] ; then
                        echo "$NR_OF_SERVERS servers found in registry, $TOTAL_NR_OF_SERVERS required. waiting 2s." >&2
                        sleep 2
                        COUNT=$(($COUNT + 1))
                fi
        done
        if [ $NR_OF_SERVERS -lt $TOTAL_NR_OF_SERVERS ] ; then
                echo "Failed to acquire the required number of services" >&2
                exit 1
        fi
}
{'fraction_non_alphanumeric': 0.1288623595505618, 'fraction_numerical': 0.016853932584269662, 'mean_word_length': 2.1903695408734603, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6938382', 'n_tokens_mistral': 1005, 'n_tokens_neox': 940, 'n_words': 199}