Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Make `load_sample_data` more resilient (#2479)

Dhruv Bhanushalia1bd5ff5fed1
diff --git a/ingestion_server/justfile b/ingestion_server/justfile
index 4bb4531eb..41d565cce 100644
--- a/ingestion_server/justfile
+++ b/ingestion_server/justfile
@@ -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":
diff --git a/load_sample_data.sh b/load_sample_data.sh
index 9f9673970..e9815d875 100755
--- a/load_sample_data.sh
+++ b/load_sample_data.sh
@@ -12,7 +12,7 @@ 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);
@@ -20,8 +20,20 @@ function load_sample_data {
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 #