2024-02-06 12:09:47 +01:00
#!/bin/bash
2024-08-26 12:55:51 +02:00
exec >> /home/azureuser/dbt_run.log 2>& 1
2024-05-30 16:38:39 +02:00
# Define the Slack webhook URL
2024-05-30 16:12:51 +02:00
script_dir = $( dirname " $0 " )
2024-05-30 16:38:39 +02:00
webhooks_file = "slack_webhook_urls.txt"
env_file = " $script_dir / $webhooks_file "
2024-05-30 16:12:51 +02:00
if [ -f " $env_file " ] ; then
export $( grep -v '^#' " $env_file " | xargs)
else
2024-05-30 16:38:39 +02:00
echo " Error: $webhooks_file file not found in the script directory. "
2024-05-30 16:12:51 +02:00
exit 1
fi
# Messages to be sent to Slack
2024-05-30 16:38:39 +02:00
slack_failure_message = ":rotating_light::rotating_light::rotating_light: One or more failures during scheduled dbt run in production. :rotating_light::rotating_light::rotating_light:"
2024-05-30 16:12:51 +02:00
slack_success_message = ":white_check_mark::white_check_mark::white_check_mark: dbt run executed successfully in production. :white_check_mark::white_check_mark::white_check_mark:"
# Initialize the failure flag
has_any_step_failed = 0
2024-02-06 12:09:47 +01:00
cd /home/azureuser/data-dwh-dbt-project
# Update from git
2024-08-26 12:55:51 +02:00
echo "Updating dbt project from git."
git checkout master
git pull
2024-02-06 12:09:47 +01:00
# Activate venv
source venv/bin/activate
2024-03-06 12:07:51 +01:00
# Run seeds
2024-08-26 12:55:51 +02:00
echo "Triggering dbt seed"
dbt seed
2024-05-30 16:12:51 +02:00
if [ $? -ne 0 ] ; then
has_any_step_failed = 1
fi
2024-03-06 12:07:51 +01:00
2024-05-10 00:31:27 +02:00
# Run staging layer
2024-08-26 12:55:51 +02:00
echo "Triggering dbt run: Staging"
dbt run -s models/staging
2024-05-30 16:12:51 +02:00
if [ $? -ne 0 ] ; then
has_any_step_failed = 1
fi
2024-05-10 00:31:27 +02:00
# Run intermediate layer
2024-08-26 12:55:51 +02:00
echo "Triggering dbt run: Intermediate"
dbt run -s models/intermediate
2024-05-30 16:12:51 +02:00
if [ $? -ne 0 ] ; then
has_any_step_failed = 1
fi
2024-05-10 00:31:27 +02:00
# Run reporting layer
2024-08-26 12:55:51 +02:00
echo "Triggering dbt run: Reporting"
dbt run -s models/reporting
2024-05-30 16:12:51 +02:00
if [ $? -ne 0 ] ; then
has_any_step_failed = 1
fi
# Check if any step failed and send a Slack message
if [ $has_any_step_failed -eq 1 ] ; then
2024-05-30 16:38:39 +02:00
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
2024-05-30 16:12:51 +02:00
fi