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

Fix to retry download API #365

Merged
merged 1 commit into from
Oct 24, 2023
Merged
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
41 changes: 32 additions & 9 deletions scripts/save_daily_csv_export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,41 @@ CURRENT_DATE=$(date +"%m_%d_%Y")
FILE_DIR="/lantern-project/onc-open-data/lantern-daily-data/$YEAR/$MONTH"
FILE_NAME=${CURRENT_DATE}endpointdata.csv
mkdir -p $FILE_DIR

log_file="/etc/lantern/logs/daily.txt"
EXPORTFILE="/etc/lantern/dailyexport/$FILE_NAME"
echo $EXPORTFILE
#URL="http://127.0.0.1:8989/api/download"
URL="https://lantern.healthit.gov/api/daily/download"
curl -o "$EXPORTFILE" "$URL"
mv "$EXPORTFILE" "$FILE_DIR/$FILE_NAME"
expected_response_code=200
max_attempts=10 # Number of times to attempt the request
current_datetime=$(date +"%Y-%m-%d %H:%M:%S")

attempts=0
echo "$current_datetime - Starting daily download.." >> $log_file
while [ $attempts -lt $max_attempts ]; do
response_code=$(curl -s -o "$EXPORTFILE" -w "%{http_code}" "$URL")

echo "$current_datetime - response code is $response_code" >> $log_file
if [ $response_code -eq $expected_response_code ]; then
current_datetime=$(date +"%Y-%m-%d %H:%M:%S")
echo "$current_datetime - Received a 200 OK response. Writing to GitHub repo." >> $log_file
mv "$EXPORTFILE" "$FILE_DIR/$FILE_NAME"
cd $FILE_DIR
git pull
git checkout main
git add $FILE_NAME
git commit -m "Adding daily export file ${FILE_NAME}"
git push --set-upstream origin main
echo "$current_datetime - Done writing to GitHub repo" >> $log_file
break
else
echo "$current_datetime - Received response code $response_code. Retrying in 3 mins..." >> $log_file
sleep 180
fi

cd $FILE_DIR
((attempts++))
done

git pull
git checkout main
git add $FILE_NAME
git commit -m "Adding daily export file ${FILE_NAME}"
git push --set-upstream origin main
if [ $attempts -eq $max_attempts ]; then
echo "Maximum number of attempts reached. Exiting."
fi
Loading