Skip to content

Instantly share code, notes, and snippets.

irb(main):001:0> Delayed::Job.find("1").last_error
Paperclip::Errors::InfiniteInterpolationError
/usr/home/myapp/vendor/bundle/ruby/2.2.0/gems/paperclip-4.2.1/lib/paperclip/interpolations.rb:53:in `url'
/usr/home/myapp/vendor/bundle/ruby/2.2.0/gems/paperclip-4.2.1/lib/paperclip/interpolations.rb:34:in `block (2 levels) in interpolate'
/usr/home/myapp/vendor/bundle/ruby/2.2.0/gems/paperclip-4.2.1/lib/paperclip/interpolations.rb:33:in `gsub'
/usr/home/myapp/vendor/bundle/ruby/2.2.0/gems/paperclip-4.2.1/lib/paperclip/interpolations.rb:33:in `block in interpolate'
/usr/home/myapp/vendor/bundle/ruby/2.2.0/gems/paperclip-4.2.1/lib/paperclip/interpolations.rb:32:in `each'
/usr/home/myapp/vendor/bundle/ruby/2.2.0/gems/paperclip-4.2.1/lib/paperclip/interpolations.rb:32:in `inject'
/usr/home/myapp/vendor/bundle/ruby/2.2.0/gems/paperclip-4.2.1/lib/paperclip/interpolations.rb:32:in `interpolate'

In this scenario

views/articles/_post.html.erb

<%= render partial: "shared/info" %>

views/stories/_post.html.erb

<%= render partial: "shared/info" %>

The way DelayedJob works is, it serializes the model, sticks it into the db … till it can be processed. Then it re-marshals it … but this process is fragile.

For example, this bit in the is_animated_gif? method: attachment.queued_for_write[:original]

… that “queued_for_write” … Paperclip stores the uploaded image in a Tmpfile until it gets uploaded to S3. This is not something that could be serialized. The Tmpfile is probably deleted before the DelayedJob runs. Also, I remember during one Paperclip upgrade, they broke that method … I don’t think it works the same way in newer versions.

paperclip-av-transcoder + paperclip-qtfaststart

Started POST "/default/topics" for ::ffff at 2015-04-05 14:05:33 +0000                                                                      
Processing by Forem::TopicsController#create as HTML                                                                                                    
  Parameters: {"utf8"=>"�~\~S", "authenticity_token"=>"+6Ma4fmBeexCEFsP9z8b5Af5vJQKarMssAxFdIHMHGEkRcP09T/zgmlVAM4Trb2iHWkHVFGFrHBqO3E8GGAzJw==", "topic
"=>{"subject"=>"sfgfgsfg", "posts_attributes"=>{"0"=>{"text"=>"sfhsg", "photos_attributes"=>{"0"=>{"attachment"=>#<ActionDispatch::Http::UploadedFile:0x
00000004502798 @tempfile=#<File:/tmp/RackMultipart20150405-50-183sbay.gif>, @original_filename="test.gif", @content_type="image/gif", @headers="Content-
Disposition: form-data; name=\"topic[posts_attributes][0][photos_attributes][0][attachment]\"; filename=\"test.gif\"\r\nContent-Type: imag

What makes this an infinite loop?

class Photo < ActiveRecord::Base
  attr_accessor :applicable_styles

  before_post_process :setup_styles

  def applicable_styles
 @applicable_styles || setup_styles

InfiniteInterpolationError

Paperclip model which checks an upload (its temp file) whether it's an animated GIF. If so it sets attachment_is_animated in the db to true. But, because this job needs to go into the background (DelayedJob), the temp file is probably gone by the time it's needed, which is most likely what's causing the InfiniteInterpolationError.


Live app which you can run on the fly: http://runnable.com/VXMNrsiY_6Fd-YRn/paperclip-delayedjob-infiniteinterpolationerror (remember to run bin/delayed_job start before hitting the big green Run button)


Replacing paperclip-ffmpeg with paperclip-av-transcoder

Live app with instructions: http://runnable.com/VR3jBtJKSwh21EKs/paperclip-av-transcoder

Problem

LoadError in Forem::TopicsController#create
cannot load such file -- /root/rails-repo/lib/paperclip_processors/qtfaststart.rb

Extracted source (around line #274):

Fetching affiliate products in Rails with Delayed::Job and Ajax

Straight forward fetching products from the affiliate API takes up to 8 seconds which is intolerable.

Demo app: https://github.com/dt1973/ajax-affiliates

Problem

How to set up the callback?