Skip to content

Commit 4494c4a

Browse files
authored
feat(scripts): reprocess.sh — paste a link, package gets re-processed end to end (#70)
1 parent f0d0e2f commit 4494c4a

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

scripts/reprocess.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Force a Discord package to be re-processed end to end.
4+
#
5+
# Deletes any existing DB row + S3 blob for the package, then re-submits
6+
# the link to /process. Useful for retrying a package that errored or
7+
# timed out, or for testing changes to the worker.
8+
#
9+
# Usage:
10+
# scripts/reprocess.sh "https://click.discord.com/ls/click?upn=u001.xyz..."
11+
#
12+
# Optional env vars:
13+
# API_BASE — defaults to https://api.dumpus.app
14+
15+
set -euo pipefail
16+
17+
if [ "$#" -ne 1 ]; then
18+
echo "usage: $0 <discord-package-link>" >&2
19+
exit 2
20+
fi
21+
22+
link="$1"
23+
api="${API_BASE:-https://api.dumpus.app}"
24+
25+
# Pull the UPN out of the link (the part after upn=).
26+
upn="${link#*upn=}"
27+
if [ "$upn" = "$link" ] || [ -z "$upn" ]; then
28+
echo "could not extract upn from link" >&2
29+
exit 1
30+
fi
31+
32+
# package_id = md5(upn)
33+
if command -v md5sum >/dev/null; then
34+
package_id=$(printf '%s' "$upn" | md5sum | awk '{print $1}')
35+
else
36+
# macOS
37+
package_id=$(printf '%s' "$upn" | md5)
38+
fi
39+
40+
echo "package_id: $package_id"
41+
echo "api: $api"
42+
43+
echo
44+
echo "1. DELETE existing package data (404 is fine if it doesn't exist)"
45+
http_code=$(curl -sS -o /tmp/reprocess-delete.json -w "%{http_code}" \
46+
-X DELETE "$api/process/$package_id" \
47+
-H "Authorization: Bearer $upn") || true
48+
echo " -> HTTP $http_code"
49+
cat /tmp/reprocess-delete.json 2>/dev/null && echo
50+
51+
echo
52+
echo "2. POST /process with the link"
53+
curl -sS -X POST "$api/process" \
54+
-H 'Content-Type: application/json' \
55+
-d "{\"package_link\":\"$link\"}" | tee /tmp/reprocess-post.json
56+
echo
57+
58+
echo
59+
echo "3. Poll /status (Ctrl+C when you've seen enough)"
60+
while true; do
61+
curl -sS "$api/process/$package_id/status" \
62+
-H "Authorization: Bearer $upn" \
63+
| python3 -c "import sys,json; d=json.load(sys.stdin); print(f\"step={d.get('processingStep')} errored={d.get('isErrored')} code={d.get('errorMessageCode')}\")"
64+
sleep 3
65+
done

0 commit comments

Comments
 (0)