Skip to content
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: 10 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ FROM php:8.3-fpm-alpine AS development
# add other deps for dev here
RUN apk add --no-cache \
libzip-dev \
bash
bash \
jq \
curl

COPY --from=composer:2.8 /usr/bin/composer /usr/bin/composer
COPY --from=jsmin /usr/bin/jsmin /usr/bin/jsmin
Expand All @@ -30,6 +32,13 @@ RUN composer install --no-interaction

COPY /exe ./exe

RUN chmod +x /opt/findingaid/exe/findingaid-cache-regen/fa-regen \
/opt/findingaid/exe/findingaid-cache-regen/fa-full-regen \
/opt/findingaid/exe/findingaid-cache-regen/fetch-ead-arks && \
ln -s /opt/findingaid/exe/findingaid-cache-regen/fa-regen /usr/local/bin/fa-regen && \
ln -s /opt/findingaid/exe/findingaid-cache-regen/fa-full-regen /usr/local/bin/fa-full-regen && \
ln -s /opt/findingaid/exe/findingaid-cache-regen/fetch-ead-arks /usr/local/bin/fetch-ead-arks

COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

Expand Down
89 changes: 81 additions & 8 deletions exe/findingaid-cache-regen/fa-full-regen
Original file line number Diff line number Diff line change
@@ -1,17 +1,90 @@
#!/bin/bash
set -euo pipefail

# The environment should provide these variables
# SOLR_URL: e.g. https://solrhost.example.com/solr/select
usage() {
cat <<'EOF'
Usage: fa-full-regen [-v|--verbose]

Regenerate the cached page for every finding aid Solr lists as a collection.

Options:
-v, --verbose List every ARK that could not be regenerated. Without it only
the count is reported
-h, --help Show this help.

Environment:
SOLR_URL Required, e.g. https://solrhost.example.com/solr/select
EOF
}

VERBOSE=0

while [ $# -gt 0 ]; do
case "$1" in
-v|--verbose) VERBOSE=1 ;;
-h|--help) usage; exit 0 ;;
*)
echo "fa-full-regen: unknown option: $1" >&2
usage >&2
exit 2
;;
esac
shift
done

ARKS_FILE="$(mktemp)"
export ARKS_FILE

trap 'rm -f "$ARKS_FILE"' EXIT
ERRORS_FILE="$(mktemp)"

trap 'rm -f "$ARKS_FILE" "$ERRORS_FILE"' EXIT

echo "Attempting generation of a list of finding aids to reprocess"
echo "Attempting generation of a list of finding aids to regenerate"
fetch-ead-arks
echo "List generated"
echo "Reprocessing finding aids"
xargs -n 1 -P 4 fa-regen < "$ARKS_FILE"
echo "Finding aids reprocessed"
FOUND=$(wc -l < "$ARKS_FILE")

PROCESSED=0

if [ "$FOUND" -le 0 ]; then
echo "$FOUND findingaid records found. Exiting..."
exit 0
fi

echo "$FOUND findingaid IDs found. Regenerating findingaids..."

function print_progress {
PROCESSED=$((PROCESSED + 1))
local PROGRESS_PERCENTAGE=$(( 100 * PROCESSED / FOUND ))
local PROGRESS_STR="["
local HASH_COUNT=$(( PROGRESS_PERCENTAGE / 5 ))
local i
for i in {1..20}; do
if [ "$i" -le $HASH_COUNT ]; then
PROGRESS_STR+="#"
else
PROGRESS_STR+=" "
fi
done
PROGRESS_STR+="] "
PROGRESS_STR+="($PROGRESS_PERCENTAGE%)"
echo -ne "$PROGRESS_STR\r"
}

xargs -n 1 -P 4 fa-regen < "$ARKS_FILE" 2> "$ERRORS_FILE" | while read -r _; do
print_progress
done
printf '\n'

# Missing EADs are a data condition, not a failed run, so report and exit 0.
if [ -s "$ERRORS_FILE" ]; then
MISSING=$(wc -l < "$ERRORS_FILE")
if [ "$VERBOSE" -eq 1 ]; then
echo "$MISSING of $FOUND finding aids could not be regenerated:" >&2
cat "$ERRORS_FILE" >&2
else
echo "$MISSING of $FOUND finding aids could not be regenerated" \
"(re-run with --verbose for the list)" >&2
fi
fi

echo "$((FOUND - MISSING)) finding aids reprocessed"
13 changes: 12 additions & 1 deletion exe/findingaid-cache-regen/fa-regen
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,15 @@ TARGET_URL=http://web
ID=$1
BASE="$TARGET_URL/fa/findingaid/?id=$ID&invalidate_cache=1"
echo "$BASE"
curl "$BASE" >/dev/null

# A finding aid whose EAD is missing from the pairtree redirects to /
STATUS=$(curl -sS -o /dev/null -w '%{http_code}' "$BASE") || STATUS=000

case "$STATUS" in
2??) ;;
302) echo "$ID: not found (redirected to /); no EAD in the pairtree" >&2 ;;
000) echo "$ID: request to $TARGET_URL failed" >&2 ;;
*) echo "$ID: unexpected HTTP $STATUS" >&2 ;;
esac

exit 0
26 changes: 18 additions & 8 deletions exe/findingaid-cache-regen/fetch-ead-arks
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
#!/bin/bash
set -euo pipefail

# The environment should provide these variables
# SOLR_URL: e.g. https://solrhost.example.com/solr/select
# ARKS_FILE: where ARKs should be written
if [[ -z "$SOLR_URL" ]]; then
echo "fetch-ead-arks: SOLR_URL must not be empty, e.g. https://solrhost.example.com/solr/select" >&2
exit 1
fi

COUNT_URL="${SOLR_URL}?wt=json&fl=id&fq=format:collections"
numFound=$(curl -s "$COUNT_URL" | jq -r .response.numFound)
echo "Found $numFound collections"
if [[ -z "$ARKS_FILE" ]]; then
echo "fetch-ead-arks: ARKS_FILE must not be empty" >&2
exit 1
fi

COUNT_URL="${SOLR_URL}?wt=json&fl=id&fq=format:collections&rows=0"
NUM_FOUND=$(curl -s "$COUNT_URL" | jq -r '.response.numFound')

if ! [[ "$NUM_FOUND" =~ ^[0-9]+$ ]]; then
echo "fetch-ead-arks: unexpected response from Solr: $NUM_FOUND" >&2
exit 1
fi

echo "Fetching ids"
EADS_URL="${SOLR_URL}?wt=json&fl=id&fq=format:collections&rows=${numFound}"
EADS_URL="${SOLR_URL}?wt=json&fl=id&fq=format:collections&rows=${NUM_FOUND}"
curl -s "$EADS_URL" | jq -r '.response.docs[] | .id' > "$ARKS_FILE"

echo "IDs written to $ARKS_FILE"
echo "List of IDs fetched successfully"
Loading