Skip to content

Commit

Permalink
Add rake task to regerate derivatives
Browse files Browse the repository at this point in the history
  • Loading branch information
jahseng-lee committed May 24, 2024
1 parent 0efd05d commit 7759507
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/tasks/banner_images.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace :banner_images do
desc "Generates derivates for banner images"
task generate_derivatives: :environment do
BannerImage.find_each do |banner_image|
attacher = banner_image.image_attacher

next unless attacher.stored?

attacher.create_derivatives

begin
attacher.atomic_persist # persist changes if attachment has not changed in the meantime
rescue Shrine::AttachmentChanged, # attachment has changed
ActiveRecord::RecordNotFound # record has been deleted
attacher.delete_derivatives # delete now orphaned derivatives
end
end
end
end

0 comments on commit 7759507

Please sign in to comment.