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.
This commit is contained in:
Arpit Jalan 2021-07-07 16:57:24 +05:30 committed by GitHub
parent 2a1abe9ff0
commit 935aadbfdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 7 deletions

View File

@ -1038,8 +1038,9 @@ def fix_missing_s3
# we do not fix sha, it may be wrong for arbitrary reasons, if we correct it # we do not fix sha, it may be wrong for arbitrary reasons, if we correct it
# we may end up breaking posts # we may end up breaking posts
upload.assign_attributes(etag: fixed_upload.etag, url: fixed_upload.url, verification_status: Upload.verification_statuses[:unchecked]) 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)
if saved
OptimizedImage.where(upload_id: upload.id).destroy_all OptimizedImage.where(upload_id: upload.id).destroy_all
rebake_ids = PostUpload.where(upload_id: upload.id).pluck(:post_id) rebake_ids = PostUpload.where(upload_id: upload.id).pluck(:post_id)
@ -1049,6 +1050,9 @@ def fix_missing_s3
post.rebake! post.rebake!
end end
end end
else
puts "Failed to save upload #{saved.errors.full_messages}"
end
end end
end end
end end