Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/solid_queue/recurring_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def ensure_existing_job_class
end

def using_solid_queue_adapter?
job_class.queue_adapter_name.inquiry.solid_queue?
job_class.queue_adapter.is_a?(ActiveJob::QueueAdapters::SolidQueueAdapter)
end

def enqueue_and_record(run_at:)
Expand Down
2 changes: 1 addition & 1 deletion lib/active_job/batch_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def batch
private

def solid_queue_job?
self.class.queue_adapter_name == "solid_queue"
self.class.queue_adapter.is_a?(ActiveJob::QueueAdapters::SolidQueueAdapter)
end
end
end
15 changes: 15 additions & 0 deletions test/models/solid_queue/batch_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ class OtherAdapterCallbackJob < ApplicationJob
def perform; end
end

class SubclassedSolidQueueAdapter < ActiveJob::QueueAdapters::SolidQueueAdapter; end

class SubclassedAdapterJob < ApplicationJob
self.queue_adapter = SubclassedSolidQueueAdapter.new

def perform; end
end

class HookedCallbackJob < ApplicationJob
cattr_accessor :enqueue_hook_ran, default: false

Expand Down Expand Up @@ -181,6 +189,13 @@ def perform; end
assert_equal 0, SolidQueue::Job.where(class_name: AbortingCallbackJob.name).count
end

test "jobs using a subclass of the Solid Queue adapter belong to the batch" do
batch = SolidQueue::Batch.enqueue { SubclassedAdapterJob.perform_later }

assert_equal 1, batch.jobs.count
assert_equal batch.id, SolidQueue::Job.where(class_name: SubclassedAdapterJob.name).sole.batch_id
end

test "callback jobs enqueue through solid_queue regardless of their class adapter" do
batch = SolidQueue::Batch.enqueue(on_finish: OtherAdapterCallbackJob) do
NiceJob.perform_later("world")
Expand Down
18 changes: 18 additions & 0 deletions test/models/solid_queue/recurring_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ def perform
end
end

class SubclassedSolidQueueAdapter < ActiveJob::QueueAdapters::SolidQueueAdapter; end

class JobUsingSubclassedSolidQueueAdapter < ApplicationJob
self.queue_adapter = SubclassedSolidQueueAdapter.new

def perform
JobBuffer.add "job_using_subclassed_solid_queue_adapter"
end
end

class JobWithConcurrencyControlsAndDiscard < ApplicationJob
limits_concurrency key: -> { true }, on_conflict: :discard

Expand Down Expand Up @@ -87,6 +97,14 @@ def perform
assert_equal "job_using_async_adapter", JobBuffer.last_value
end

test "job using a subclass of the Solid Queue adapter" do
task = recurring_task_with(class_name: "JobUsingSubclassedSolidQueueAdapter")

assert_difference -> { SolidQueue::RecurringExecution.count }, +1 do
enqueue_and_assert_performed_with_result task, "job_using_subclassed_solid_queue_adapter"
end
end

test "error when enqueuing job before recording task" do
SolidQueue::Job.stubs(:create!).raises(ActiveRecord::Deadlocked)

Expand Down
Loading