delayed_paperclip 2.10.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -4
- data/Appraisals +1 -13
- data/README.md +41 -95
- data/delayed_paperclip.gemspec +7 -8
- data/gemfiles/5.0.gemfile +1 -1
- data/lib/delayed_paperclip.rb +3 -13
- data/lib/delayed_paperclip/process_job.rb +14 -0
- data/lib/delayed_paperclip/railtie.rb +10 -15
- data/lib/delayed_paperclip/version.rb +1 -1
- data/spec/delayed_paperclip/attachment_spec.rb +0 -1
- data/spec/delayed_paperclip/class_methods_spec.rb +0 -1
- data/spec/delayed_paperclip/instance_methods_spec.rb +0 -1
- data/spec/delayed_paperclip/url_generator_spec.rb +0 -1
- data/spec/delayed_paperclip_spec.rb +15 -22
- data/spec/integration/base_delayed_paperclip_spec.rb +0 -5
- data/spec/integration/examples/base.rb +6 -4
- data/spec/integration/process_job_spec.rb +26 -0
- data/spec/spec_helper.rb +7 -11
- metadata +22 -84
- data/gemfiles/3.2.gemfile +0 -7
- data/gemfiles/4.0.gemfile +0 -7
- data/gemfiles/4.1.gemfile +0 -7
- data/init.rb +0 -4
- data/lib/delayed_paperclip/jobs.rb +0 -8
- data/lib/delayed_paperclip/jobs/active_job.rb +0 -14
- data/lib/delayed_paperclip/jobs/delayed_job.rb +0 -46
- data/lib/delayed_paperclip/jobs/resque.rb +0 -22
- data/lib/delayed_paperclip/jobs/sidekiq.rb +0 -30
- data/rails/init.rb +0 -2
- data/spec/integration/active_job_inline_spec.rb +0 -26
- data/spec/integration/active_job_resque_spec.rb +0 -28
- data/spec/integration/active_job_sidekiq_spec.rb +0 -34
- data/spec/integration/delayed_job_spec.rb +0 -63
- data/spec/integration/resque_spec.rb +0 -47
- data/spec/integration/sidekiq_spec.rb +0 -54
data/gemfiles/3.2.gemfile
DELETED
data/gemfiles/4.0.gemfile
DELETED
data/gemfiles/4.1.gemfile
DELETED
data/init.rb
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
module DelayedPaperclip
|
2
|
-
module Jobs
|
3
|
-
autoload :ActiveJob, 'delayed_paperclip/jobs/active_job'
|
4
|
-
autoload :DelayedJob, 'delayed_paperclip/jobs/delayed_job'
|
5
|
-
autoload :Resque, 'delayed_paperclip/jobs/resque'
|
6
|
-
autoload :Sidekiq, 'delayed_paperclip/jobs/sidekiq'
|
7
|
-
end
|
8
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module DelayedPaperclip
|
2
|
-
module Jobs
|
3
|
-
class ActiveJob < ActiveJob::Base
|
4
|
-
def self.enqueue_delayed_paperclip(instance_klass, instance_id, attachment_name)
|
5
|
-
queue_name = instance_klass.constantize.paperclip_definitions[attachment_name][:delayed][:queue]
|
6
|
-
set(:queue => queue_name).perform_later(instance_klass, instance_id, attachment_name.to_s)
|
7
|
-
end
|
8
|
-
|
9
|
-
def perform(instance_klass, instance_id, attachment_name)
|
10
|
-
DelayedPaperclip.process_job(instance_klass, instance_id, attachment_name.to_sym)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'delayed_job'
|
2
|
-
require 'active_support/deprecation'
|
3
|
-
|
4
|
-
module DelayedPaperclip
|
5
|
-
module Jobs
|
6
|
-
class DelayedJob < Struct.new(:instance_klass, :instance_id, :attachment_name)
|
7
|
-
|
8
|
-
# This is available in newer versions of DelayedJob. Using the newee Job api thus.
|
9
|
-
if Gem.loaded_specs['delayed_job'].version >= Gem::Version.new("2.1.0")
|
10
|
-
|
11
|
-
def self.enqueue_delayed_paperclip(instance_klass, instance_id, attachment_name)
|
12
|
-
ActiveSupport::Deprecation.warn(<<-MESSAGE)
|
13
|
-
Using DelayedJob adapter for delayed_paperclip is deprecated and will be removed in version 3.0.0.
|
14
|
-
Please use ActiveJob adapter.
|
15
|
-
MESSAGE
|
16
|
-
|
17
|
-
::Delayed::Job.enqueue(
|
18
|
-
:payload_object => new(instance_klass, instance_id, attachment_name),
|
19
|
-
:priority => instance_klass.constantize.paperclip_definitions[attachment_name][:delayed][:priority].to_i,
|
20
|
-
:queue => instance_klass.constantize.paperclip_definitions[attachment_name][:delayed][:queue]
|
21
|
-
)
|
22
|
-
end
|
23
|
-
|
24
|
-
else
|
25
|
-
|
26
|
-
def self.enqueue_delayed_paperclip(instance_klass, instance_id, attachment_name)
|
27
|
-
ActiveSupport::Deprecation.warn(<<-MESSAGE)
|
28
|
-
Using DelayedJob adapter for delayed_paperclip is deprecated and will be removed in version 3.0.0.
|
29
|
-
Please use ActiveJob adapter.
|
30
|
-
MESSAGE
|
31
|
-
|
32
|
-
::Delayed::Job.enqueue(
|
33
|
-
new(instance_klass, instance_id, attachment_name),
|
34
|
-
instance_klass.constantize.paperclip_definitions[attachment_name][:delayed][:priority].to_i,
|
35
|
-
instance_klass.constantize.paperclip_definitions[attachment_name][:delayed][:queue]
|
36
|
-
)
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
def perform
|
42
|
-
DelayedPaperclip.process_job(instance_klass, instance_id, attachment_name)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'resque'
|
2
|
-
require 'active_support/deprecation'
|
3
|
-
|
4
|
-
module DelayedPaperclip
|
5
|
-
module Jobs
|
6
|
-
class Resque
|
7
|
-
def self.enqueue_delayed_paperclip(instance_klass, instance_id, attachment_name)
|
8
|
-
@queue = instance_klass.constantize.paperclip_definitions[attachment_name][:delayed][:queue]
|
9
|
-
::Resque.enqueue(self, instance_klass, instance_id, attachment_name)
|
10
|
-
|
11
|
-
ActiveSupport::Deprecation.warn(<<-MESSAGE)
|
12
|
-
Using Resque adapter for delayed_paperclip is deprecated and will be removed in version 3.0.0.
|
13
|
-
Please use ActiveJob adapter.
|
14
|
-
MESSAGE
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.perform(instance_klass, instance_id, attachment_name)
|
18
|
-
DelayedPaperclip.process_job(instance_klass, instance_id, attachment_name)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'sidekiq/worker'
|
2
|
-
require 'active_support/deprecation'
|
3
|
-
|
4
|
-
module DelayedPaperclip
|
5
|
-
module Jobs
|
6
|
-
class Sidekiq
|
7
|
-
include ::Sidekiq::Worker
|
8
|
-
|
9
|
-
def self.enqueue_delayed_paperclip(instance_klass, instance_id, attachment_name)
|
10
|
-
ActiveSupport::Deprecation.warn(<<-MESSAGE)
|
11
|
-
Using Sidekiq adapter for delayed_paperclip is deprecated and will be removed in version 3.0.0.
|
12
|
-
Please use ActiveJob adapter.
|
13
|
-
MESSAGE
|
14
|
-
|
15
|
-
queue_name = instance_klass.constantize.paperclip_definitions[attachment_name][:delayed][:queue]
|
16
|
-
# Sidekiq >= 4.1.0
|
17
|
-
if respond_to?(:set)
|
18
|
-
set(:queue => queue_name)
|
19
|
-
else
|
20
|
-
sidekiq_options :queue => queue_name
|
21
|
-
end
|
22
|
-
perform_async(instance_klass, instance_id, attachment_name)
|
23
|
-
end
|
24
|
-
|
25
|
-
def perform(instance_klass, instance_id, attachment_name)
|
26
|
-
DelayedPaperclip.process_job(instance_klass, instance_id, attachment_name)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/rails/init.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "ActiveJob inline" do
|
4
|
-
if defined? ActiveJob
|
5
|
-
before :each do
|
6
|
-
DelayedPaperclip.options[:background_job_class] = DelayedPaperclip::Jobs::ActiveJob
|
7
|
-
ActiveJob::Base.queue_adapter = :inline
|
8
|
-
ActiveJob::Base.logger = nil
|
9
|
-
end
|
10
|
-
|
11
|
-
let(:dummy) { Dummy.new(:image => File.open("#{ROOT}/fixtures/12k.png")) }
|
12
|
-
|
13
|
-
describe "perform job" do
|
14
|
-
before :each do
|
15
|
-
DelayedPaperclip.options[:url_with_processing] = true
|
16
|
-
reset_dummy
|
17
|
-
end
|
18
|
-
|
19
|
-
it "performs a job" do
|
20
|
-
dummy.image = File.open("#{ROOT}/fixtures/12k.png")
|
21
|
-
Paperclip::Attachment.any_instance.expects(:reprocess!)
|
22
|
-
dummy.save!
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'resque'
|
3
|
-
|
4
|
-
if defined? ActiveJob
|
5
|
-
describe "Active Job with Resque backend" do
|
6
|
-
before :each do
|
7
|
-
DelayedPaperclip.options[:background_job_class] = DelayedPaperclip::Jobs::ActiveJob
|
8
|
-
ActiveJob::Base.logger = nil
|
9
|
-
ActiveJob::Base.queue_adapter = :resque
|
10
|
-
Resque.remove_queue(:paperclip)
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:dummy) { Dummy.new(:image => File.open("#{ROOT}/fixtures/12k.png")) }
|
14
|
-
|
15
|
-
describe "integration tests" do
|
16
|
-
include_examples "base usage"
|
17
|
-
end
|
18
|
-
|
19
|
-
def process_jobs
|
20
|
-
worker = Resque::Worker.new(:paperclip)
|
21
|
-
worker.process
|
22
|
-
end
|
23
|
-
|
24
|
-
def jobs_count(queue = :paperclip)
|
25
|
-
Resque.size(queue)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'sidekiq/testing'
|
3
|
-
|
4
|
-
describe "ActiveJob with Sidekiq backend" do
|
5
|
-
if defined? ActiveJob
|
6
|
-
before :each do
|
7
|
-
DelayedPaperclip.options[:background_job_class] = DelayedPaperclip::Jobs::ActiveJob
|
8
|
-
ActiveJob::Base.logger = nil
|
9
|
-
ActiveJob::Base.queue_adapter = :sidekiq
|
10
|
-
Sidekiq::Queues["paperclip"].clear
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:dummy) { Dummy.new(:image => File.open("#{ROOT}/fixtures/12k.png")) }
|
14
|
-
|
15
|
-
describe "integration tests" do
|
16
|
-
include_examples "base usage"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def process_jobs
|
21
|
-
Sidekiq::Queues["paperclip"].each do |job|
|
22
|
-
worker = job["class"].constantize.new
|
23
|
-
args = job["args"]
|
24
|
-
begin
|
25
|
-
worker.perform(*args)
|
26
|
-
rescue # Assume sidekiq handle exception properly
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def jobs_count(queue = "paperclip")
|
32
|
-
Sidekiq::Queues[queue].size
|
33
|
-
end
|
34
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'delayed_job'
|
3
|
-
|
4
|
-
Delayed::Worker.backend = :active_record
|
5
|
-
|
6
|
-
describe "Delayed Job" do
|
7
|
-
before :each do
|
8
|
-
DelayedPaperclip.options[:background_job_class] = DelayedPaperclip::Jobs::DelayedJob
|
9
|
-
build_delayed_jobs
|
10
|
-
end
|
11
|
-
|
12
|
-
let(:dummy) { Dummy.new(:image => File.open("#{ROOT}/fixtures/12k.png")) }
|
13
|
-
|
14
|
-
describe "integration tests" do
|
15
|
-
include_examples "base usage"
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "perform job" do
|
19
|
-
before :each do
|
20
|
-
DelayedPaperclip.options[:url_with_processing] = true
|
21
|
-
reset_dummy
|
22
|
-
end
|
23
|
-
|
24
|
-
it "performs a job" do
|
25
|
-
dummy.image = File.open("#{ROOT}/fixtures/12k.png")
|
26
|
-
Paperclip::Attachment.any_instance.expects(:reprocess!)
|
27
|
-
dummy.save!
|
28
|
-
Delayed::Job.last.payload_object.perform
|
29
|
-
end
|
30
|
-
|
31
|
-
it "is deprecated" do
|
32
|
-
ActiveSupport::Deprecation.expects(:warn)
|
33
|
-
|
34
|
-
dummy.image = File.open("#{ROOT}/fixtures/12k.png")
|
35
|
-
Paperclip::Attachment.any_instance.expects(:reprocess!)
|
36
|
-
dummy.save!
|
37
|
-
Delayed::Job.last.payload_object.perform
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def process_jobs
|
42
|
-
Delayed::Worker.new.work_off
|
43
|
-
end
|
44
|
-
|
45
|
-
def jobs_count(queue = nil)
|
46
|
-
Delayed::Job.count
|
47
|
-
end
|
48
|
-
|
49
|
-
def build_delayed_jobs
|
50
|
-
ActiveRecord::Base.connection.create_table :delayed_jobs, :force => true do |table|
|
51
|
-
table.integer :priority, :default => 0 # Allows some jobs to jump to the front of the queue
|
52
|
-
table.integer :attempts, :default => 0 # Provides for retries, but still fail eventually.
|
53
|
-
table.text :handler # YAML-encoded string of the object that will do work
|
54
|
-
table.string :last_error # reason for last failure (See Note below)
|
55
|
-
table.datetime :run_at # When to run. Could be Time.now for immediately, or sometime in the future.
|
56
|
-
table.datetime :locked_at # Set when a client is working on this object
|
57
|
-
table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
|
58
|
-
table.string :locked_by # Who is working on this object (if locked)
|
59
|
-
table.string :queue
|
60
|
-
table.timestamps null: true
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'resque'
|
3
|
-
|
4
|
-
describe "Resque" do
|
5
|
-
before :each do
|
6
|
-
DelayedPaperclip.options[:background_job_class] = DelayedPaperclip::Jobs::Resque
|
7
|
-
Resque.remove_queue(:paperclip)
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:dummy) { Dummy.new(:image => File.open("#{ROOT}/fixtures/12k.png")) }
|
11
|
-
|
12
|
-
describe "integration tests" do
|
13
|
-
include_examples "base usage"
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "perform job" do
|
17
|
-
before :each do
|
18
|
-
DelayedPaperclip.options[:url_with_processing] = true
|
19
|
-
reset_dummy
|
20
|
-
end
|
21
|
-
|
22
|
-
it "performs a job" do
|
23
|
-
dummy.image = File.open("#{ROOT}/fixtures/12k.png")
|
24
|
-
Paperclip::Attachment.any_instance.expects(:reprocess!)
|
25
|
-
dummy.save!
|
26
|
-
DelayedPaperclip::Jobs::Resque.perform(dummy.class.name, dummy.id, :image)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "is deprecated" do
|
30
|
-
ActiveSupport::Deprecation.expects(:warn)
|
31
|
-
|
32
|
-
dummy.image = File.open("#{ROOT}/fixtures/12k.png")
|
33
|
-
Paperclip::Attachment.any_instance.expects(:reprocess!)
|
34
|
-
dummy.save!
|
35
|
-
DelayedPaperclip::Jobs::Resque.perform(dummy.class.name, dummy.id, :image)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def process_jobs
|
40
|
-
worker = Resque::Worker.new(:paperclip)
|
41
|
-
worker.process
|
42
|
-
end
|
43
|
-
|
44
|
-
def jobs_count(queue = :paperclip)
|
45
|
-
Resque.size(queue)
|
46
|
-
end
|
47
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'sidekiq/testing'
|
3
|
-
|
4
|
-
describe "Sidekiq" do
|
5
|
-
before :each do
|
6
|
-
Sidekiq.logger.level = Logger::ERROR
|
7
|
-
DelayedPaperclip.options[:background_job_class] = DelayedPaperclip::Jobs::Sidekiq
|
8
|
-
Sidekiq::Queues["paperclip"].clear
|
9
|
-
end
|
10
|
-
|
11
|
-
let(:dummy) { Dummy.new(:image => File.open("#{ROOT}/fixtures/12k.png")) }
|
12
|
-
|
13
|
-
describe "integration tests" do
|
14
|
-
include_examples "base usage"
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "perform job" do
|
18
|
-
before :each do
|
19
|
-
DelayedPaperclip.options[:url_with_processing] = true
|
20
|
-
reset_dummy
|
21
|
-
end
|
22
|
-
|
23
|
-
it "performs a job" do
|
24
|
-
dummy.image = File.open("#{ROOT}/fixtures/12k.png")
|
25
|
-
Paperclip::Attachment.any_instance.expects(:reprocess!)
|
26
|
-
dummy.save!
|
27
|
-
DelayedPaperclip::Jobs::Sidekiq.new.perform(dummy.class.name, dummy.id, :image)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "is deprecated" do
|
31
|
-
ActiveSupport::Deprecation.expects(:warn)
|
32
|
-
|
33
|
-
dummy.image = File.open("#{ROOT}/fixtures/12k.png")
|
34
|
-
Paperclip::Attachment.any_instance.expects(:reprocess!)
|
35
|
-
dummy.save!
|
36
|
-
DelayedPaperclip::Jobs::Sidekiq.new.perform(dummy.class.name, dummy.id, :image)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def process_jobs
|
41
|
-
Sidekiq::Queues["paperclip"].each do |job|
|
42
|
-
worker = job["class"].constantize.new
|
43
|
-
args = job["args"]
|
44
|
-
begin
|
45
|
-
worker.perform(*args)
|
46
|
-
rescue # Assume sidekiq handle exception properly
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def jobs_count(queue = "paperclip")
|
52
|
-
Sidekiq::Queues[queue].size
|
53
|
-
end
|
54
|
-
end
|