-
Notifications
You must be signed in to change notification settings - Fork 10
/
idr-data.sh
executable file
·46 lines (36 loc) · 1.43 KB
/
idr-data.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh
# chmod +x this file to make it executable
SERVICE_NAME="Identity Resolver"
# Max number of retries
MAX_RETRIES=3
RETRY_COUNT=0
# Path to the IDR identifier JSON file
IDENTIFIER_FILE="./seeding/idr-identifier.json"
# Wait for the service to be available
echo "Waiting for ${SERVICE_NAME} service to be ready..."
# Loop until the health API returns "status": "OK"
while true; do
# If max retries reached, exit with error
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
echo "${SERVICE_NAME} service did not become healthy after $MAX_RETRIES attempts. Exiting..."
exit 1
fi
# Make the health check request and store the status
HEALTH_STATUS=$(curl -s http://${IDR_SERVICE_HOST}:${IDR_SERVICE_PORT}/health-check | grep -o '"status":"OK"')
if [ "$HEALTH_STATUS" = '"status":"OK"' ]; then
echo "${SERVICE_NAME} service is healthy!"
break
fi
RETRY_COUNT=$((RETRY_COUNT+1))
echo "${SERVICE_NAME} service is not healthy yet. Retrying in 5 seconds..."
sleep 5 # Wait for 5 seconds before checking again
done
echo "${SERVICE_NAME} service is seeding data…"
# Execute create identifier request with JSON data from a file
curl -X POST \
http://${IDR_SERVICE_HOST}:${IDR_SERVICE_PORT}/api/identifiers \
-H 'accept: application/json' \
-H "Authorization: Bearer ${IDR_SERVICE_API_KEY}" \
-H 'Content-Type: application/json' \
-d @"$IDENTIFIER_FILE"
printf "\nSeeding ${SERVICE_NAME} service data complete!\n\n"