Generating thumbs in background

157 görüntüleme
İlk okunmamış mesaja atla

Clint

okunmadı,
4 Şub 2011 11:05:344.02.2011
alıcı Dragonfly
Hi,

First, thanks a lot for this great project.
I have a problem preprocessing an image with delayed_job and placing
it in the tmp folder.
I want to process an image in the background and place it in the
correct tmp/ folder, that is user for
caching.
I got the correct url after image.process(xy).thumb('XxY').url but the
file isn't actually created.
Is there a way to do this?

Nathan Hessler

okunmadı,
4 Şub 2011 11:17:534.02.2011
alıcı dragonf...@googlegroups.com
Clint,

if you want it done in the background you could use delayed job or resque or whatever, but the way to make that happen would be image.process(xy).thumb('XxY').apply although I'm not sure this would get it cached for the url call. because things get cached by dragonfly we made a primer task that will prime the caches when we need to. so we go through all the thumbs we want and build the urls and wget them thus priming the cache for all thumbnails. we don't run it often, but we definitely ran it when first standing up our app.

Clint

okunmadı,
4 Şub 2011 11:32:404.02.2011
alıcı Dragonfly
Thanks for the quick reply.
I am already using delayed_job and it generates the correct path, /
image/<long string>. Only problem is,
that the file is not generated in tmp/dragonfly/cache/body/ . When I
refresh the view, the file is generated correctly.
I just want to pregenerate this file, that is later used by the rack-
cache.


Thanks a lot!

Nathan Hessler

okunmadı,
4 Şub 2011 11:44:164.02.2011
alıcı dragonf...@googlegroups.com
so when delayed job builds the correct url it still needs to call out to it by making an http request to it. I use wget for this: `wget "http:/domain.com/image/long_string" --delete-after`. I would do this in a rake task if your images are pretty static (not adding or replacing them alot) or in the :after_save hook when an image is added or replaced or something, but not in the view. in the view it's probably too late as the browser could make the request faster than delayed job depending on how backed up it is.

Clint

okunmadı,
5 Şub 2011 08:36:515.02.2011
alıcı Dragonfly
thanks for that, I will try it out as soon as I can.

Clint

okunmadı,
7 Şub 2011 04:58:487.02.2011
alıcı Dragonfly
Works great, I used delayed_job instead of a rake task.
Thanks again for the fast and great response.

Code Daemon

okunmadı,
7 Şub 2011 16:32:107.02.2011
alıcı Dragonfly
It would be great if you could include any relevant snippets of code.

Clint

okunmadı,
8 Şub 2011 04:14:448.02.2011
alıcı Dragonfly
#assets_controller.rb
def update
## some stuff
Delayed::Job.enqueue(CropImageJob.new(@asset.id))
end


#lib/crop_image_job.rb
class CropImageJob < Struct.new(:asset_id)

def perform
puts "Cropping image with id: #{asset_id}"
asset = Asset.find(asset_id)
tempfile = asset.image.process(:resize_and_crop, :width =>
40, :height=> 50, :gravity => 'ne').url
system "wget http://localhost:3000#{tempfile} --delete-after"
asset.state = "ready"
asset.save!
puts "Image #{asset_id} successful resized and published"
end

def success(job)
puts ">>> Successful finished job: #{job.id}"
end

def failure(job)
puts ">>> Job #{job.id} failed to resize image"
end

end


This will generate the imagethumb the cache uses.
I would recommend to fire up the console and the worker with "rake
jobs:work" and test
your job with the console first. The asset.state is later used to
determine if the image
is ready for display. Use a default value of "not_ready" or something,
boolean would be suffice
here.

Skip Intro

okunmadı,
30 May 2016 19:52:5630.05.2016
alıcı Dragonfly
I am googled and found, that wget with --delete-after is commonly used to force reverse-proxe cache system to cache the contents. But does not this command cause pretty unnecessary IO operation in filesystem? Is not it possible to do something like just HEAD request with curl, so no images will be actually fully downloaded and then removed?

вторник, 8 февраля 2011 г., 12:14:44 UTC+3 пользователь Clint написал:
Tümünü yanıtla
Yazarı yanıtla
Yönlendir
0 yeni ileti