Last active
December 11, 2015 06:09
-
-
Save teaforthecat/4557534 to your computer and use it in GitHub Desktop.
Store the processed image on the datastore before being served by dragonfly (pre-caching). The url needs to be accesses programatically, like in a background job.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# store the job before it has a chance to be served by dragonfly | |
images.configure do |c| | |
c.define_url do |app, job, opts| | |
thumb = ThumbTracker.where(job: job.serialize).first | |
unless thumb | |
uid = job.store | |
thumb = ThumbTracker.create!( | |
:uid => uid, | |
:job => job.serialize | |
) | |
end | |
n = ['', 0, 1, 2].sample | |
app.datastore.url_for(thumb.uid, host: "cdn#{n}.s3.aws.com") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment