Skip to content
This repository has been archived by the owner on Oct 5, 2018. It is now read-only.

Commit

Permalink
Deprecate Resque, Sidekiq and DelayedJob adapters.
Browse files Browse the repository at this point in the history
For better maintenance of gem `delayed_paperclip` will only support
`ActiveJob` adapter which is available by default since Rails 4.2.
It's possible to use any of this 3 background job adapters through AJ.
  • Loading branch information
morgoth committed Apr 28, 2016
1 parent 854bc56 commit c2b9aa1
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,23 @@ end

### Resque

Resque adapter is deprecated. Please use ActiveJob one.

Make sure that you have [Resque](https://github.com/resque/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 workers exactly as you
would otherwise.

### DJ

DelayedJob adapter is deprecated. Please use ActiveJob one.

Just make sure that you have DJ up and running.

### Sidekiq

Sidekiq adapter is deprecated. Please use ActiveJob one.

Make sure that [Sidekiq](http://github.com/mperham/sidekiq) is running and listening to the
`paperclip` queue, either by adding it to your
`sidekiq.yml` config file under `- queues:` or by
Expand Down
11 changes: 11 additions & 0 deletions lib/delayed_paperclip/jobs/delayed_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'delayed_job'
require 'active_support/deprecation'

module DelayedPaperclip
module Jobs
Expand All @@ -8,6 +9,11 @@ class DelayedJob < Struct.new(:instance_klass, :instance_id, :attachment_name)
if Gem.loaded_specs['delayed_job'].version >= Gem::Version.new("2.1.0")

def self.enqueue_delayed_paperclip(instance_klass, instance_id, attachment_name)
ActiveSupport::Deprecation.warn(<<-MESSAGE)
Using DelayedJob adapter for delayed_paperclip is deprecated and will be removed in version 3.0.0.
Please use ActiveJob adapter.
MESSAGE

::Delayed::Job.enqueue(
:payload_object => new(instance_klass, instance_id, attachment_name),
:priority => instance_klass.constantize.paperclip_definitions[attachment_name][:delayed][:priority].to_i,
Expand All @@ -18,6 +24,11 @@ def self.enqueue_delayed_paperclip(instance_klass, instance_id, attachment_name)
else

def self.enqueue_delayed_paperclip(instance_klass, instance_id, attachment_name)
ActiveSupport::Deprecation.warn(<<-MESSAGE)
Using DelayedJob adapter for delayed_paperclip is deprecated and will be removed in version 3.0.0.
Please use ActiveJob adapter.
MESSAGE

::Delayed::Job.enqueue(
new(instance_klass, instance_id, attachment_name),
instance_klass.constantize.paperclip_definitions[attachment_name][:delayed][:priority].to_i,
Expand Down
6 changes: 6 additions & 0 deletions lib/delayed_paperclip/jobs/resque.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
require 'resque'
require 'active_support/deprecation'

module DelayedPaperclip
module Jobs
class Resque
def self.enqueue_delayed_paperclip(instance_klass, instance_id, attachment_name)
@queue = instance_klass.constantize.paperclip_definitions[attachment_name][:delayed][:queue]
::Resque.enqueue(self, instance_klass, instance_id, attachment_name)

ActiveSupport::Deprecation.warn(<<-MESSAGE)
Using Resque adapter for delayed_paperclip is deprecated and will be removed in version 3.0.0.
Please use ActiveJob adapter.
MESSAGE
end

def self.perform(instance_klass, instance_id, attachment_name)
Expand Down
6 changes: 6 additions & 0 deletions lib/delayed_paperclip/jobs/sidekiq.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
require 'sidekiq/worker'
require 'active_support/deprecation'

module DelayedPaperclip
module Jobs
class Sidekiq
include ::Sidekiq::Worker

def self.enqueue_delayed_paperclip(instance_klass, instance_id, attachment_name)
ActiveSupport::Deprecation.warn(<<-MESSAGE)
Using Sidekiq adapter for delayed_paperclip is deprecated and will be removed in version 3.0.0.
Please use ActiveJob adapter.
MESSAGE

queue_name = instance_klass.constantize.paperclip_definitions[attachment_name][:delayed][:queue]
# Sidekiq >= 4.1.0
if respond_to?(:set)
Expand Down
9 changes: 9 additions & 0 deletions spec/integration/delayed_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
dummy.save!
Delayed::Job.last.payload_object.perform
end

it "is deprecated" do
ActiveSupport::Deprecation.expects(:warn)

dummy.image = File.open("#{ROOT}/fixtures/12k.png")
Paperclip::Attachment.any_instance.expects(:reprocess!)
dummy.save!
Delayed::Job.last.payload_object.perform
end
end

def process_jobs
Expand Down
9 changes: 9 additions & 0 deletions spec/integration/resque_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
dummy.save!
DelayedPaperclip::Jobs::Resque.perform(dummy.class.name, dummy.id, :image)
end

it "is deprecated" do
ActiveSupport::Deprecation.expects(:warn)

dummy.image = File.open("#{ROOT}/fixtures/12k.png")
Paperclip::Attachment.any_instance.expects(:reprocess!)
dummy.save!
DelayedPaperclip::Jobs::Resque.perform(dummy.class.name, dummy.id, :image)
end
end

def process_jobs
Expand Down
9 changes: 9 additions & 0 deletions spec/integration/sidekiq_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
dummy.save!
DelayedPaperclip::Jobs::Sidekiq.new.perform(dummy.class.name, dummy.id, :image)
end

it "is deprecated" do
ActiveSupport::Deprecation.expects(:warn)

dummy.image = File.open("#{ROOT}/fixtures/12k.png")
Paperclip::Attachment.any_instance.expects(:reprocess!)
dummy.save!
DelayedPaperclip::Jobs::Sidekiq.new.perform(dummy.class.name, dummy.id, :image)
end
end

def process_jobs
Expand Down
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
ActiveRecord::Base.raise_in_transactional_callbacks = true
end

require "active_support/deprecation"
ActiveSupport::Deprecation.silenced = true

# Connect to sqlite
ActiveRecord::Base.establish_connection(
"adapter" => "sqlite3",
Expand Down

0 comments on commit c2b9aa1

Please sign in to comment.