From 8275641ba3732071ddf059e16ad8b7461ac7dd65 Mon Sep 17 00:00:00 2001 From: David May-Miller Date: Thu, 26 Oct 2023 15:38:56 +0100 Subject: [PATCH] CLDC-2895 Capture exceptions raised while saving and send them to Sentry --- lib/tasks/squish_names.rake | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/lib/tasks/squish_names.rake b/lib/tasks/squish_names.rake index 496bff419..697bc7d7b 100644 --- a/lib/tasks/squish_names.rake +++ b/lib/tasks/squish_names.rake @@ -1,19 +1,35 @@ desc "Squish names of locations, schemes, users, and organisations" task squish_names: :environment do - Location.find_each do |location| + Location.where("name LIKE ?", "% %").each do |location| location.name&.squish! - location.save!(validate: false) + begin + location.save! + rescue StandardError => e + Sentry.capture_exception(e) + end end - Scheme.find_each do |scheme| + Scheme.where("service_name LIKE ?", "% %").each do |scheme| scheme.service_name&.squish! - scheme.save!(validate: false) + begin + scheme.save! + rescue StandardError => e + Sentry.capture_exception(e) + end end - User.find_each do |user| + User.where("name LIKE ?", "% %").each do |user| user.name&.squish! - user.save!(validate: false) + begin + user.save! + rescue StandardError => e + Sentry.capture_exception(e) + end end - Organisation.find_each do |organisation| + Organisation.where("name LIKE ?", "% %").each do |organisation| organisation.name&.squish! - organisation.save!(validate: false) + begin + organisation.save! + rescue StandardError => e + Sentry.capture_exception(e) + end end end