Skip to content

Commit 61cadf6

Browse files
committed
Apply deprecation path instead of removal
1 parent b97acae commit 61cadf6

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

activejob/CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
* Remove `sucker_punch` as an adapter option [since author himself recommends using AJ's own AsyncAdapter](https://github.com/brandonhilkert/sucker_punch?tab=readme-ov-file#faq).
1+
* Deprecate `sucker_punch` as an adapter option.
2+
23
If you're using this adapter, change to `adapter: async` for the same functionality.
34

4-
*Dino Maric*
5+
*Dino Maric, zzak*
56

67
* Use `RAILS_MAX_THREADS` in `ActiveJob::AsyncAdapter`. If it is not set, use 5 as default.
78

activejob/lib/active_job/queue_adapter.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def queue_adapter=(name_or_adapter)
5050
case name_or_adapter
5151
when Symbol, String
5252
queue_adapter = ActiveJob::QueueAdapters.lookup(name_or_adapter).new
53+
queue_adapter.try(:check_adapter)
5354
assign_adapter(name_or_adapter.to_s, queue_adapter)
5455
else
5556
if queue_adapter?(name_or_adapter)

activejob/lib/active_job/queue_adapters/sucker_punch_adapter.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ module QueueAdapters
1818
#
1919
# Rails.application.config.active_job.queue_adapter = :sucker_punch
2020
class SuckerPunchAdapter < AbstractAdapter
21+
def check_adapter
22+
ActiveJob.deprecator.warn <<~MSG.squish
23+
The `sucker_punch` adapter is deprecated and will be removed in Rails 8.1.
24+
Please use the `async` adapter instead.
25+
MSG
26+
end
27+
2128
def enqueue(job) # :nodoc:
2229
if JobWrapper.respond_to?(:perform_async)
2330
# sucker_punch 2.0 API

activejob/test/cases/adapter_test.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,31 @@ class AdapterTest < ActiveSupport::TestCase
66
test "should load #{ENV['AJ_ADAPTER']} adapter" do
77
assert_equal "active_job/queue_adapters/#{ENV['AJ_ADAPTER']}_adapter".classify, ActiveJob::Base.queue_adapter.class.name
88
end
9+
10+
if adapter_is?(:sucker_punch)
11+
test "sucker_punch adapter should be deprecated" do
12+
before_adapter = ActiveJob::Base.queue_adapter
13+
14+
msg = <<~MSG.squish
15+
The `sucker_punch` adapter is deprecated and will be removed in Rails 8.1.
16+
Please use the `async` adapter instead.
17+
MSG
18+
assert_deprecated(msg, ActiveJob.deprecator) do
19+
ActiveJob::Base.queue_adapter = :sucker_punch
20+
end
21+
22+
ensure
23+
ActiveJob::Base.queue_adapter = before_adapter
24+
end
25+
26+
test "sucker_punch check_adapter should warn" do
27+
msg = <<~MSG.squish
28+
The `sucker_punch` adapter is deprecated and will be removed in Rails 8.1.
29+
Please use the `async` adapter instead.
30+
MSG
31+
assert_deprecated(msg, ActiveJob.deprecator) do
32+
ActiveJob::Base.queue_adapter.check_adapter
33+
end
34+
end
35+
end
936
end

0 commit comments

Comments
 (0)