Skip to content

Commit

Permalink
Merge pull request #400 from onc-healthit/LANTERN-590-data_collection…
Browse files Browse the repository at this point in the history
…_check_logs

LANTERN-590: Added logging for data collection check cron job
  • Loading branch information
vishnu-mettles authored Sep 10, 2024
2 parents dea9e38 + 75b534b commit f70d9d5
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions scripts/data_collection_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,24 @@ EMAIL=
DB_NAME=
DB_USER=
QUERY_INTERVAL=
log_file="/etc/lantern/logs/data_collection_check_logs.txt"
current_datetime=$(date +"%Y-%m-%d %H:%M:%S")

QUERY_INTERVAL_SECONDS=$((${QUERY_INTERVAL}*60))
DATE=$(date +%s)
PASTDATE=$((${DATE}-${QUERY_INTERVAL_SECONDS}))
QUERY=$(echo "SELECT count(*) FROM fhir_endpoints_info_history WHERE floor(extract(epoch from fhir_endpoints_info_history.updated_at)) BETWEEN ${PASTDATE} AND ${DATE}")
COUNT=$(docker exec -t lantern-back-end_postgres_1 psql -t -U${DB_USER} -d ${DB_NAME} -c "${QUERY}") || echo "Error: Database is down" | /usr/bin/mail -s "Cron Job Error" ${EMAIL}
COUNT=$(docker exec -t lantern-back-end_postgres_1 psql -t -U${DB_USER} -d ${DB_NAME} -c "${QUERY}") || {
echo "$current_datetime - Error: Database is down" >> $log_file
echo "Error: Database is down" | /usr/bin/mail -s "Cron Job Error" ${EMAIL}
exit 0
}
NUMBER=$(echo ${COUNT} | tr -cd '[[:digit:]]')

if [ "${NUMBER}" -eq "0" ]; then
echo "$current_datetime - Error: Lantern data collection has stopped" >> $log_file
echo "Error: Lantern data collection has stopped" | /usr/bin/mail -s "Cron Job Error" ${EMAIL}
fi
exit 0
fi

echo "$current_datetime - Lantern data collection successful" >> $log_file

0 comments on commit f70d9d5

Please sign in to comment.