delayed_paperclip 0.1.1 → 0.5.0.pre

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -2,35 +2,33 @@ h1. Delayed::Paperclip
2
2
 
3
3
  Delayed_paperclip lets you process your "Paperclip":http://github.com/thoughtbot/paperclip attachments in a background task with "delayed_job":http://github.com/tobi/delayed_job.
4
4
 
5
- h2. Why?
5
+ This is a fork that focuses on "Resque":http://github.com/defunkt/resque rather than Delayed::Job. Everyone says that "they are both awesome":http://github.com/blog/542-introducing-resque, but, in my case, I'm already committed to using "Vanity":http://vanity.labnotes.org/ and, I'm no expert, but "redis and Vanity":http://groups.google.com/group/vanity-talk/browse_thread/thread/db6c106581a26c46/eccff9396bdb2fe8?show_docid=eccff9396bdb2fe8&fwc=1&pli=1# look like they're likely to go hand in hand for some time.
6
6
 
7
- The most common use case for Paperclip is to easily attach image files to ActiveRecord models. Most of the time these image files will have multiple styles and will need to be resized when they are created. This is usually a pretty "slow operation":http://www.jstorimer.com/ruby/2010/01/05/speep-up-your-paperclip-tests.html and should be handled in a background task.
7
+ h2. Why?
8
8
 
9
- I'm sure that everyone knows this, this gem just makes it easy to do.
9
+ The "original author":http://github.com/jstorimer/delayed_paperclip says:
10
10
 
11
- h2. Installation
11
+ bq. The most common use case for Paperclip is to easily attach image files to ActiveRecord models. Most of the time these image files will have multiple styles and will need to be resized when they are created. This is usually a pretty "slow operation":http://www.jstorimer.com/ruby/2010/01/05/speep-up-your-paperclip-tests.html and should be handled in a background task.
12
12
 
13
- Install the gem:
13
+ bq. I'm sure that everyone knows this, this gem just makes it easy to do.
14
14
 
15
- <pre><code>sudo gem install delayed_paperclip</code></pre>
15
+ I am also concerned with the "memory usage of ImageMagick":http://magick.imagemagick.org/script/architecture.php#cache and didn't want a few bad actors to be able to take down my site just by uploading some big pictures.
16
16
 
17
- Add it to your environment.rb:
17
+ h2. Installation
18
18
 
19
- <pre><code>config.gem 'delayed_paperclip'</code></pre>
19
+ Not only do I have no idea how I would enable some kind of "two gems" approach, but also I don't know what the future of this project is, necessarily. But it does work, and maybe you'll find it useful.
20
20
 
21
- Or, even better, to your Gemfile:
21
+ Install as a rails plugin:
22
22
 
23
- <pre><code>source "http://gemcutter.org"
24
- gem 'delayed_paperclip'
25
- </code></pre>
23
+ <pre><code>script/plugin install git://github.com/bigfleet/delayed_paperclip.git</code></pre>
26
24
 
27
25
  Dependencies:
28
26
  * Paperclip
29
- * delayed_job
27
+ * resque
30
28
 
31
29
  h2. Usage
32
30
 
33
- Make sure that you have "DJ":http://github.com/tobi/delayed_job up and running.
31
+ Make sure that you have "Resque":http://github.com/defunkt/resque up and running. The jobs will be dispatched to the <code>:paperclip</code> queue, so you can correctly dispatch your worker. Configure resque and your worker exactly as you would otherwise.
34
32
 
35
33
  In your model:
36
34
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.5.0.pre
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{delayed_paperclip}
8
- s.version = "0.1.1"
8
+ s.version = "0.5.0.pre"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jesse Storimer"]
12
- s.date = %q{2010-02-03}
12
+ s.date = %q{2010-02-09}
13
13
  s.description = %q{Process your Paperclip attachments in the background with delayed_job.}
14
14
  s.email = %q{jesse@jstorimer.com}
15
15
  s.extra_rdoc_files = [
@@ -23,13 +23,15 @@ Gem::Specification.new do |s|
23
23
  "Rakefile",
24
24
  "VERSION",
25
25
  "delayed_paperclip.gemspec",
26
+ "lib/delayed/jobs/delayed_paperclip_job.rb",
27
+ "lib/delayed/jobs/resque_paperclip_job.rb",
26
28
  "lib/delayed/paperclip.rb",
27
- "lib/delayed/paperclip_job.rb",
28
29
  "lib/delayed_paperclip.rb",
29
30
  "rails/init.rb",
30
31
  "test/database.yml",
31
32
  "test/delayed_paperclip_test.rb",
32
33
  "test/fixtures/12k.png",
34
+ "test/resque_paperclip_test.rb",
33
35
  "test/test_helper.rb"
34
36
  ]
35
37
  s.homepage = %q{http://github.com/jstorimer/delayed_paperclip}
@@ -39,6 +41,7 @@ Gem::Specification.new do |s|
39
41
  s.summary = %q{Process your Paperclip attachments in the background with delayed_job.}
40
42
  s.test_files = [
41
43
  "test/delayed_paperclip_test.rb",
44
+ "test/resque_paperclip_test.rb",
42
45
  "test/test_helper.rb"
43
46
  ]
44
47
 
@@ -1,4 +1,4 @@
1
- class DelayedPaperclipJob < Struct.new(:instance_id, :instance_klass, :attachment_name)
1
+ class DelayedPaperclipJob < Struct.new(:instance_klass, :instance_id, :attachment_name)
2
2
  def perform
3
3
  instance = instance_klass.constantize.find(instance_id)
4
4
 
@@ -0,0 +1,9 @@
1
+ class ResquePaperclipJob
2
+ @queue = :paperclip
3
+
4
+ def self.perform(instance_klass, instance_id, attachment_name)
5
+ instance = instance_klass.constantize.find(instance_id)
6
+
7
+ instance.send(attachment_name).reprocess!
8
+ end
9
+ end
@@ -20,7 +20,11 @@ module Delayed
20
20
 
21
21
  define_method "enqueue_job_for_#{name}" do
22
22
  if self.send("#{name}_changed?")
23
- Delayed::Job.enqueue DelayedPaperclipJob.new(read_attribute(:id), self.class.name, name.to_sym)
23
+ if delayed_job?
24
+ Delayed::Job.enqueue DelayedPaperclipJob.new(read_attribute(:id), self.class.name, name.to_sym)
25
+ elsif resque?
26
+ Resque.enqueue(ResquePaperclipJob, self.class.name, read_attribute(:id), name.to_sym)
27
+ end
24
28
  end
25
29
  end
26
30
 
@@ -42,6 +46,14 @@ module Delayed
42
46
 
43
47
  false
44
48
  end
49
+
50
+ def delayed_job?
51
+ defined? Delayed::Job
52
+ end
53
+
54
+ def resque?
55
+ defined? Resque
56
+ end
45
57
  end
46
58
  end
47
59
  end
@@ -1,7 +1,6 @@
1
- require 'paperclip'
2
- require 'delayed_job'
3
1
  require 'delayed/paperclip'
4
- require 'delayed/paperclip_job'
2
+ require 'delayed/jobs/resque_paperclip_job'
3
+ require 'delayed/jobs/delayed_paperclip_job'
5
4
 
6
5
  if Object.const_defined?("ActiveRecord")
7
6
  ActiveRecord::Base.send(:include, Delayed::Paperclip)
@@ -1,4 +1,6 @@
1
1
  require 'test/test_helper'
2
+ gem 'delayed_job'
3
+ require 'delayed_job'
2
4
 
3
5
  class DelayedPaperclipTest < Test::Unit::TestCase
4
6
  def setup
@@ -44,36 +46,23 @@ class DelayedPaperclipTest < Test::Unit::TestCase
44
46
 
45
47
  original_job_count = Delayed::Job.count
46
48
  @dummy.enqueue_job_for_image
47
-
49
+
48
50
  assert_equal original_job_count + 1, Delayed::Job.count
49
51
  end
50
-
52
+
51
53
  def test_perform_job
52
54
  Paperclip::Attachment.any_instance.expects(:reprocess!)
53
-
55
+
54
56
  @dummy.save!
55
- DelayedPaperclipJob.new(@dummy.id, @dummy.class.name, :image).perform
57
+ DelayedPaperclipJob.new(@dummy.class.name, @dummy.id, :image).perform
56
58
  end
57
-
59
+
58
60
  def test_after_callback_is_functional
59
61
  @dummy_class.send(:define_method, :done_processing) { puts 'done' }
60
62
  @dummy_class.after_image_post_process :done_processing
61
63
  Dummy.any_instance.expects(:done_processing)
62
64
 
63
65
  @dummy.save!
64
- DelayedPaperclipJob.new(@dummy.id, @dummy.class.name, :image).perform
65
- end
66
-
67
- private
68
- def reset_dummy
69
- reset_table("dummies") do |d|
70
- d.string :image_file_name
71
- d.integer :image_file_size
72
- end
73
- @dummy_class = reset_class "Dummy"
74
- @dummy_class.has_attached_file :image
75
- @dummy_class.process_in_background :image
76
-
77
- @dummy = Dummy.new(:image => File.open("#{RAILS_ROOT}/test/fixtures/12k.png"))
66
+ DelayedPaperclipJob.new(@dummy.class.name, @dummy.id, :image).perform
78
67
  end
79
68
  end
@@ -0,0 +1,37 @@
1
+ require 'test/test_helper'
2
+ gem 'resque'
3
+ require 'resque'
4
+
5
+ class ResquePaperclipTest < Test::Unit::TestCase
6
+ def setup
7
+ # Make sure that we just test Resque in here
8
+ Object.send(:remove_const, :Delayed) if defined? Delayed
9
+
10
+ reset_dummy
11
+ end
12
+
13
+ def test_enqueue_job_if_source_changed
14
+ @dummy.stubs(:image_changed?).returns(true)
15
+
16
+ original_job_count = Resque.size(:paperclip)
17
+ @dummy.enqueue_job_for_image
18
+
19
+ assert_equal original_job_count + 1, Resque.size(:paperclip)
20
+ end
21
+
22
+ def test_perform_job
23
+ Paperclip::Attachment.any_instance.expects(:reprocess!)
24
+
25
+ @dummy.save!
26
+ ResquePaperclipJob.perform(@dummy.class.name, @dummy.id, :image)
27
+ end
28
+
29
+ def test_after_callback_is_functional
30
+ @dummy_class.send(:define_method, :done_processing) { puts 'done' }
31
+ @dummy_class.after_image_post_process :done_processing
32
+ Dummy.any_instance.expects(:done_processing)
33
+
34
+ @dummy.save!
35
+ ResquePaperclipJob.perform(@dummy.class.name, @dummy.id, :image)
36
+ end
37
+ end
data/test/test_helper.rb CHANGED
@@ -6,10 +6,9 @@ require 'active_record'
6
6
  require 'active_support'
7
7
 
8
8
  gem 'sqlite3-ruby'
9
+
9
10
  gem 'paperclip'
10
11
  require 'paperclip'
11
- gem 'delayed_job'
12
- require 'delayed_job'
13
12
 
14
13
  FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
15
14
  config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
@@ -24,11 +23,6 @@ $LOAD_PATH << File.join(ROOT, 'lib')
24
23
  $LOAD_PATH << File.join(ROOT, 'lib', 'delayed', 'paperclip')
25
24
  $LOAD_PATH << File.join(ROOT, 'test')
26
25
 
27
- module ActiveRecord
28
- class Base
29
- end
30
- end
31
-
32
26
  require File.join(ROOT, 'lib', 'delayed_paperclip.rb')
33
27
 
34
28
  def reset_class class_name
@@ -69,6 +63,18 @@ def rebuild_class options = {}
69
63
  end
70
64
  end
71
65
 
66
+ def reset_dummy
67
+ reset_table("dummies") do |d|
68
+ d.string :image_file_name
69
+ d.integer :image_file_size
70
+ end
71
+ @dummy_class = reset_class "Dummy"
72
+ @dummy_class.has_attached_file :image
73
+ @dummy_class.process_in_background :image
74
+
75
+ @dummy = Dummy.new(:image => File.open("#{RAILS_ROOT}/test/fixtures/12k.png"))
76
+ end
77
+
72
78
  def build_delayed_jobs
73
79
  ActiveRecord::Base.connection.create_table :delayed_jobs, :force => true do |table|
74
80
  table.integer :priority, :default => 0 # Allows some jobs to jump to the front of the queue
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayed_paperclip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.5.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Storimer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-03 00:00:00 -05:00
12
+ date: 2010-02-09 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -38,13 +38,15 @@ files:
38
38
  - Rakefile
39
39
  - VERSION
40
40
  - delayed_paperclip.gemspec
41
+ - lib/delayed/jobs/delayed_paperclip_job.rb
42
+ - lib/delayed/jobs/resque_paperclip_job.rb
41
43
  - lib/delayed/paperclip.rb
42
- - lib/delayed/paperclip_job.rb
43
44
  - lib/delayed_paperclip.rb
44
45
  - rails/init.rb
45
46
  - test/database.yml
46
47
  - test/delayed_paperclip_test.rb
47
48
  - test/fixtures/12k.png
49
+ - test/resque_paperclip_test.rb
48
50
  - test/test_helper.rb
49
51
  has_rdoc: true
50
52
  homepage: http://github.com/jstorimer/delayed_paperclip
@@ -63,9 +65,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
65
  version:
64
66
  required_rubygems_version: !ruby/object:Gem::Requirement
65
67
  requirements:
66
- - - ">="
68
+ - - ">"
67
69
  - !ruby/object:Gem::Version
68
- version: "0"
70
+ version: 1.3.1
69
71
  version:
70
72
  requirements: []
71
73
 
@@ -76,4 +78,5 @@ specification_version: 3
76
78
  summary: Process your Paperclip attachments in the background with delayed_job.
77
79
  test_files:
78
80
  - test/delayed_paperclip_test.rb
81
+ - test/resque_paperclip_test.rb
79
82
  - test/test_helper.rb