From bf3868d806a48d504eca5cc51516d159ea7f6ff2 Mon Sep 17 00:00:00 2001 From: GeoWill Date: Thu, 21 Nov 2024 13:46:50 +0000 Subject: [PATCH] Make import_eoni_from_s3 command report to slack --- deploy/files/scripts/import_eoni_from_s3.sh | 14 ++++++++++++-- .../management/commands/import_eoni.py | 7 +++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/deploy/files/scripts/import_eoni_from_s3.sh b/deploy/files/scripts/import_eoni_from_s3.sh index 1a598794c7..950a5f1156 100644 --- a/deploy/files/scripts/import_eoni_from_s3.sh +++ b/deploy/files/scripts/import_eoni_from_s3.sh @@ -2,7 +2,11 @@ set -e set -x -DC_ENVIRONMENT=$DC_ENVIRONMENT +if [ -z "$DC_ENVIRONMENT" ]; then + echo "DC_ENVIRONMENT is not set" + exit 1 +fi + BUCKET_NAME="eoni-data.wheredoivote.co.uk.${DC_ENVIRONMENT}" SRCDIR='/tmp/eoni_production_data' PREM_4326_CSV=${SRCDIR}/PREM_4326.csv @@ -10,6 +14,12 @@ PRO_4326_CSV=${SRCDIR}/PRO_4326.csv LATEST_FILE=$(/usr/local/bin/aws s3 ls s3://"${BUCKET_NAME}/" | sort | tail -n1 | rev | cut -d' ' -f1 | rev) +if [ "$DC_ENVIRONMENT" = "production" ]; then + SLACK_CHANNEL="bots" +else + SLACK_CHANNEL="bot-testing" +fi + rm -rf $SRCDIR && mkdir -p $SRCDIR /usr/local/bin/aws s3 cp s3://"${BUCKET_NAME}/${LATEST_FILE}" $SRCDIR @@ -26,6 +36,6 @@ mlr --icsv --otsv --headerless-csv-output cut -f PRO_X_COR,PRO_Y_COR $SRCDIR/"${ paste -d ',' ${PRO_4326_CSV} ${PREM_4326_CSV} $SRCDIR/"${LATEST_FILE}" > eoni_reprojected.csv -/usr/bin/manage-py-command import_eoni --cleanup --reprojected eoni_reprojected.csv +/usr/bin/manage-py-command import_eoni --cleanup --reprojected --slack ${SLACK_CHANNEL} eoni_reprojected.csv rm ${PREM_4326_CSV} ${PRO_4326_CSV} eoni_reprojected.csv diff --git a/polling_stations/apps/data_importers/management/commands/import_eoni.py b/polling_stations/apps/data_importers/management/commands/import_eoni.py index 007a966752..fb2573b21c 100644 --- a/polling_stations/apps/data_importers/management/commands/import_eoni.py +++ b/polling_stations/apps/data_importers/management/commands/import_eoni.py @@ -90,10 +90,9 @@ def handle(self, *args, **options): } self.stations_only = options.get("stations_only") self.pre_process_data(reprojected=options["reprojected"]) - with transaction.atomic(): - self.clear_old_data() - self.copy_data() - self.assign_uprn_to_councils() + self.clear_old_data() + self.copy_data() + self.assign_uprn_to_councils() super().handle(*args, **options) if options.get("cleanup"): [path.unlink() for path in self.paths.values() if path.exists()]