DEV: fix_missing_s3 attempts to re-download if missing

unverified uploads get re-downloaded and corrected if they exist in the task
This commit is contained in:
Sam Saffron 2020-08-13 11:22:14 +10:00
parent bd0a7553c4
commit f48fa30ecd
No known key found for this signature in database
GPG Key ID: B9606168D2FFD9F5
1 changed files with 21 additions and 0 deletions

View File

@ -1065,6 +1065,27 @@ end
def fix_missing_s3
Jobs.run_immediately!
puts "Attempting to download missing uploads and recreate"
ids = Upload.where(verified: false).pluck(:id)
ids.each do |id|
upload = Upload.find(id)
tempfile = FileHelper.download(upload.url, max_file_size: 30.megabyte, tmp_file_name: "#{SecureRandom.hex}.#{upload.extension}")
if tempfile
puts "Successfully downloaded upload id: #{upload.id} - #{upload.url} fixing upload"
fixed_upload = nil
Upload.transaction do
upload.update!(sha1: SecureRandom.hex)
fixed_upload = UploadCreator.new(tempfile, "temp.#{upload.extension}").create_for(Discourse.system_user.id)
raise ActiveRecord::Rollback
end
upload.update!(etag: fixed_upload.etag, sha1: fixed_upload.sha1, url: fixed_upload.url, verified: nil)
end
end
puts "Attempting to automatically fix problem uploads"
puts
puts "Rebaking posts with missing uploads, this can take a while as all rebaking runs inline"