mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
a869d861f4
This reverts https://github.com/discourse/discourse/commit/9d8db11c If the job fails during execution or if `SiteSetting.migrate_to_new_scheme` has been set to `false`, the job will be considered as executed even though the migration has not been completed. As a result, the job will have to be executed manually which is not desirable.
37 lines
1.2 KiB
Ruby
37 lines
1.2 KiB
Ruby
module Jobs
|
|
|
|
class MigrateUploadScheme < Jobs::Scheduled
|
|
every 10.minutes
|
|
sidekiq_options retry: false
|
|
|
|
def execute(args)
|
|
return unless SiteSetting.migrate_to_new_scheme
|
|
|
|
# clean up failed uploads
|
|
Upload.where("created_at < ?", 1.hour.ago)
|
|
.where("LENGTH(COALESCE(url, '')) = 0")
|
|
.destroy_all
|
|
|
|
# migrate uploads to new scheme
|
|
problems = Upload.migrate_to_new_scheme(50)
|
|
problems.each do |hash|
|
|
upload_id = hash[:upload].id
|
|
Discourse.handle_job_exception(hash[:ex], error_context(args, "Migrating upload id #{upload_id}", upload_id: upload_id))
|
|
end
|
|
|
|
# clean up failed optimized images
|
|
OptimizedImage.where("LENGTH(COALESCE(url, '')) = 0").destroy_all
|
|
# Clean up orphan optimized images
|
|
OptimizedImage.where("upload_id NOT IN (SELECT id FROM uploads)").destroy_all
|
|
|
|
# migrate optimized_images to new scheme
|
|
problems = OptimizedImage.migrate_to_new_scheme(50)
|
|
problems.each do |hash|
|
|
optimized_image_id = hash[:optimized_image].id
|
|
Discourse.handle_job_exception(hash[:ex], error_context(args, "Migrating optimized_image id #{optimized_image_id}", optimized_image_id: optimized_image_id))
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
end
|