Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make load_sample_data more resilient #2479

Merged
merged 3 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines +72 to +75
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was surprised by this because I assumed cURL supported some kind of method for changing the exit code if the status was bad. It turns out there's a relatively new feature (2021) that does this: --fail-with-body. It has the added benefit of still printing the response body with the failure without needing to add any more flags (or checks).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't use that because a lot of us are developing on macOS and might have an older version of cURL built-in. Installing a new version of cURL is technically an option but I experienced SSL issues when I last did that and I didn't want to force an additional system-level dependency.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, TIL that macOS is on an old version 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not only cURL, macOS comes bundled with plenty of old utils.

I also had problems with Git when I tried to use some new feature (can't recall what it was), didn't have it, installed Git with Brew which then refused to work with SSH proto. It was a whole thing to reset everything 😢.


# 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