From cc6d57e80f96c71f21d70d6bcf22d8c61e301487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Wn=C4=99trzak?= Date: Thu, 28 Apr 2016 18:45:47 +0200 Subject: [PATCH] Deprecate Resque, Sidekiq and DelayedJob adapters. 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. --- README.md | 6 ++++++ lib/delayed_paperclip/jobs/delayed_job.rb | 11 +++++++++++ lib/delayed_paperclip/jobs/resque.rb | 6 ++++++ lib/delayed_paperclip/jobs/sidekiq.rb | 6 ++++++ spec/integration/delayed_job_spec.rb | 9 +++++++++ spec/integration/resque_spec.rb | 9 +++++++++ spec/integration/sidekiq_spec.rb | 9 +++++++++ spec/spec_helper.rb | 3 +++ 8 files changed, 59 insertions(+) diff --git a/README.md b/README.md index cbfae32..305f05e 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,8 @@ 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 :paperclip queue, so you can correctly dispatch your worker. Configure resque and your workers exactly as you @@ -90,10 +92,14 @@ 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 diff --git a/lib/delayed_paperclip/jobs/delayed_job.rb b/lib/delayed_paperclip/jobs/delayed_job.rb index 586cc37..3e6ba1c 100644 --- a/lib/delayed_paperclip/jobs/delayed_job.rb +++ b/lib/delayed_paperclip/jobs/delayed_job.rb @@ -1,4 +1,5 @@ require 'delayed_job' +require 'active_support/deprecation' module DelayedPaperclip module Jobs @@ -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, @@ -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, diff --git a/lib/delayed_paperclip/jobs/resque.rb b/lib/delayed_paperclip/jobs/resque.rb index 8f36817..5528aed 100644 --- a/lib/delayed_paperclip/jobs/resque.rb +++ b/lib/delayed_paperclip/jobs/resque.rb @@ -1,4 +1,5 @@ require 'resque' +require 'active_support/deprecation' module DelayedPaperclip module Jobs @@ -6,6 +7,11 @@ 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) diff --git a/lib/delayed_paperclip/jobs/sidekiq.rb b/lib/delayed_paperclip/jobs/sidekiq.rb index 0f66278..80aede0 100644 --- a/lib/delayed_paperclip/jobs/sidekiq.rb +++ b/lib/delayed_paperclip/jobs/sidekiq.rb @@ -1,4 +1,5 @@ require 'sidekiq/worker' +require 'active_support/deprecation' module DelayedPaperclip module Jobs @@ -6,6 +7,11 @@ 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) diff --git a/spec/integration/delayed_job_spec.rb b/spec/integration/delayed_job_spec.rb index cace22a..7581311 100644 --- a/spec/integration/delayed_job_spec.rb +++ b/spec/integration/delayed_job_spec.rb @@ -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 diff --git a/spec/integration/resque_spec.rb b/spec/integration/resque_spec.rb index 52b1990..008f9fe 100644 --- a/spec/integration/resque_spec.rb +++ b/spec/integration/resque_spec.rb @@ -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 diff --git a/spec/integration/sidekiq_spec.rb b/spec/integration/sidekiq_spec.rb index 715c5b4..3ceb805 100644 --- a/spec/integration/sidekiq_spec.rb +++ b/spec/integration/sidekiq_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 686cfe3..ad8d234 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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",