From eb4a3ce0d93cbc2392058ca6b22ad14733b23882 Mon Sep 17 00:00:00 2001 From: Matchu Date: Fri, 10 Nov 2023 17:42:56 -0800 Subject: [PATCH] More gracefully handle batches that fail to save I noticed a thing with like, an asset that I think referenced an item that doesn't exist, which caused an error in the `body_specific?` validation step? Tbh that validation step needs fixed up in a number of ways, but I'm scared to, since it's hard to know what will break modeling lol. But in any case, more graceful handling is nice! If something happens, I'd rather leave it null and try again later than have the job crash! --- lib/tasks/swf_assets.rake | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/tasks/swf_assets.rake b/lib/tasks/swf_assets.rake index ebff4fcb..309833a6 100644 --- a/lib/tasks/swf_assets.rake +++ b/lib/tasks/swf_assets.rake @@ -57,7 +57,19 @@ namespace :swf_assets do # for the transactional semantics, but because it's notably faster than # doing a commit between each query, which is what sending the queries # individually would effectively do!) - SwfAsset.transaction { batch.each(&:save!) } + begin + SwfAsset.transaction do + batch.each do |asset| + begin + asset.save! + rescue StandardError => error + puts "⚠️ Saving asset #{asset.id} failed: #{error.full_message}" + end + end + end + rescue StandardError => error + puts "⚠️ Saving this batch failed: #{error.full_message}" + end end end end