From 935aadbfddc6ece3742163e9d878a75617292e64 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Wed, 7 Jul 2021 16:57:24 +0530 Subject: [PATCH] FIX: do not stop `fix_missing_s3` task if saving an upload failed (#13658) This commit logs an error and moves to next upload when saving a single upload record fails when running `uploads:fix_missing_s3` task. --- lib/tasks/uploads.rake | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/tasks/uploads.rake b/lib/tasks/uploads.rake index 2915cd2fb10..4ae945cc9d5 100644 --- a/lib/tasks/uploads.rake +++ b/lib/tasks/uploads.rake @@ -1038,16 +1038,20 @@ def fix_missing_s3 # we do not fix sha, it may be wrong for arbitrary reasons, if we correct it # we may end up breaking posts upload.assign_attributes(etag: fixed_upload.etag, url: fixed_upload.url, verification_status: Upload.verification_statuses[:unchecked]) - upload.save!(validate: false) + saved = upload.save(validate: false) - OptimizedImage.where(upload_id: upload.id).destroy_all - rebake_ids = PostUpload.where(upload_id: upload.id).pluck(:post_id) + if saved + OptimizedImage.where(upload_id: upload.id).destroy_all + rebake_ids = PostUpload.where(upload_id: upload.id).pluck(:post_id) - if rebake_ids.present? - Post.where(id: rebake_ids).each do |post| - puts "rebake post #{post.id}" - post.rebake! + if rebake_ids.present? + Post.where(id: rebake_ids).each do |post| + puts "rebake post #{post.id}" + post.rebake! + end end + else + puts "Failed to save upload #{saved.errors.full_messages}" end end end