2024-06-13 18:21:18 +02:00
#!/bin/bash
2024-06-14 11:50:48 +02:00
exec >> /home/azureuser/xexe_run.log 2>& 1
echo " Starting script at $( date) "
2024-06-13 18:21:18 +02:00
# Define the Slack webhook URL
script_dir = $( dirname " $0 " )
webhooks_file = "slack_webhook_urls.txt"
env_file = " $script_dir / $webhooks_file "
if [ -f " $env_file " ] ; then
export $( grep -v '^#' " $env_file " | xargs)
else
echo " Error: $webhooks_file file not found in the script directory. "
exit 1
fi
# Messages to be sent to Slack
2024-06-13 19:19:37 +02:00
slack_failure_message = ":rotating_light::rotating_light::rotating_light: One or more failures during scheduled xexe run in production. :rotating_light::rotating_light::rotating_light:"
slack_success_message = ":white_check_mark::white_check_mark::white_check_mark: xexe run executed successfully in production. :white_check_mark::white_check_mark::white_check_mark:"
2024-06-13 18:21:18 +02:00
# Initialize the failure flag
has_any_step_failed = 0
cd /home/azureuser/data-xexe
# Update from git
2024-06-14 11:50:48 +02:00
echo "Updating xexe project from git."
git checkout master
git pull
2024-06-13 18:21:18 +02:00
2024-06-14 12:08:25 +02:00
# Make poetry available
echo "Including Poetry in PATH"
export PATH = " $HOME /.local/bin: $PATH "
2024-06-13 18:21:18 +02:00
# DWH-healthcheck
2024-06-14 11:50:48 +02:00
echo "Running DWH healthcheck..."
poetry run xexe dwh-healthcheck
2024-06-13 18:21:18 +02:00
if [ $? -ne 0 ] ; then
has_any_step_failed = 1
2024-06-14 11:50:48 +02:00
echo "Something went wrong when healthchecking DWH."
2024-06-13 18:21:18 +02:00
fi
# xe healthcheck
2024-06-14 11:50:48 +02:00
echo "Running XE.com healthcheck..."
poetry run xexe xe-healthcheck
2024-06-13 18:21:18 +02:00
if [ $? -ne 0 ] ; then
has_any_step_failed = 1
2024-06-14 11:50:48 +02:00
echo "Something went wrong when healthchecking xe.com."
2024-06-13 18:21:18 +02:00
fi
2024-06-13 19:18:40 +02:00
# Define some options here. You might want to change this some day.
2024-06-27 16:41:09 +02:00
currencies = "CAD,EUR,NZD,ZAR,AUD,USD,PLN,GBP,CHF"
2024-06-13 19:18:40 +02:00
start_date = $( date -d "yesterday" +"%Y-%m-%d" )
end_date = $( date -d "yesterday" +"%Y-%m-%d" )
2024-06-13 18:21:18 +02:00
# run the actual thing
2024-06-14 11:50:48 +02:00
echo "Getting rates from xe.com..."
poetry run xexe get-rates --currencies " $currencies " --start-date " $start_date " --end-date " $end_date " --rates-source xe --output dwh --ignore-warnings
2024-06-13 18:21:18 +02:00
if [ $? -ne 0 ] ; then
has_any_step_failed = 1
2024-06-14 11:50:48 +02:00
echo "Something went wrong when getting rates."
2024-06-13 18:21:18 +02:00
fi
# Check if any step failed and send a Slack message
if [ $has_any_step_failed -eq 1 ] ; then
curl -X POST -H 'Content-type: application/json' --data " {\"text\":\" $slack_failure_message \"} " $SLACK_ALERT_WEBHOOK_URL
fi
if [ $has_any_step_failed -eq 0 ] ; then
curl -X POST -H 'Content-type: application/json' --data " {\"text\":\" $slack_success_message \"} " $SLACK_RECEIPT_WEBHOOK_URL
fi