Skip to content

Commit

Permalink
Make load_sample_data more resilient (#2479)
Browse files Browse the repository at this point in the history
Co-authored-by: Zack Krida <[email protected]>
  • Loading branch information
dhruvkb and zackkrida authored Jun 26, 2023
1 parent 3e982b5 commit a1bd5ff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
11 changes: 8 additions & 3 deletions ingestion_server/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,17 @@ wait-up: up

# Make a cURL POST request to the service with the given data
_curl-post data host="localhost:50281":
curl \
STATUS_CODE=$(curl \
-X POST \
-H 'Content-Type: application/json' \
-d '{{ data }}' \
-w "\n" \
'http://{{ host }}/task'
-o /dev/stderr \
-w "%{http_code}" \
'http://{{ host }}/task'); \
if [ $STATUS_CODE -lt 200 ] || [ $STATUS_CODE -ge 300 ]; then \
echo "Status: $STATUS_CODE"; \
exit 1; \
fi

# Load sample data into temp table in API and new index in Elasticsearch
ingest-upstream model="image" suffix="init":
Expand Down
14 changes: 13 additions & 1 deletion load_sample_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,28 @@ DB_SERVICE_NAME="${DB_SERVICE_NAME:-db}"
# Load sample data
function load_sample_data {
docker-compose exec -T "$UPSTREAM_DB_SERVICE_NAME" bash -c "psql <<-EOF
DELETE FROM $1;
DELETE FROM $1;
\copy $1 \
from './sample_data/sample_$1.csv' \
with (FORMAT csv, HEADER true);
REFRESH MATERIALIZED VIEW $1_view;
EOF"
}

function verify_loaded_data {
COUNT=$(docker-compose exec -T "$UPSTREAM_DB_SERVICE_NAME" bash -c "psql -AXqt <<-EOF
SELECT COUNT(*) FROM $1;
EOF")
if [ "$COUNT" -ne 5000 ]; then
echo "Error: table $1 count differs from expected."
exit 1
fi
}

load_sample_data "image"
verify_loaded_data "image"
load_sample_data "audio"
verify_loaded_data "audio"

#######
# API #
Expand Down

0 comments on commit a1bd5ff

Please sign in to comment.