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

Deprecate Resque, Sidekiq and DelayedJob adapters. #178

Merged
merged 1 commit into from May 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
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
@@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@morgoth did you have a chance to double check whether this shows up in the main server log and not just background job logs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it shows on server logs, as it's done when enqueuing, not performing.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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
@@ -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
@@ -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
Expand Up @@ -27,6 +27,15 @@
dummy.save!
Delayed::Job.last.payload_object.perform
end

it "is deprecated" do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the test

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
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
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
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