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 lib/active_job/queue_adapters/async_job_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def enqueue(job)
# @parameter job [ActiveJob::Base] The job to enqueue.
# @parameter timestamp [Time] The time at which to enqueue the job.
def enqueue_at(job, timestamp)
job.scheduled_at = timestamp
job.scheduled_at ||= Time.at(timestamp)
Copy link
Author

@davidalejandroaguilar davidalejandroaguilar Oct 26, 2025

Choose a reason for hiding this comment

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

Again, since this is an Active Job adapter, I'd suggest just removing it since we know jobs will already come with scheduled_at set, but I'm leaving it there just in case we want to guarantee that #enqueue_at sets it on the job when passing a timestamp.

I understand that commit 3b4fd0b - Fix handling of scheduled jobs. added this so there might be a more nuanced reason why we make sure its set here, so that's yet another reason why I'm not blindly removing it.


Sync do
@dispatcher.call(job)
Expand Down
38 changes: 35 additions & 3 deletions test/active_job/queue_adapters/async_job_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@
end

it "can enqueue a job at specific time" do
adapter.enqueue_at(job, timestamp)
adapter.enqueue_at(job, timestamp.to_f)

Sync do
serialized_job = buffer.pop
expect(serialized_job).to have_keys(
"job_class" => be == "TestJob",
"queue_name" => be == "default",
"arguments" => be == [],
"scheduled_at" => be == timestamp.iso8601(9),
"scheduled_at" => be == job.scheduled_at.iso8601(9),
)
end
end
Expand All @@ -93,7 +93,39 @@
# This test verifies that the job gets dispatched successfully at a specific time
# The Sync wrapper is tested implicitly by the successful enqueueing
expect(dispatcher.queues["default"]).to be_a(Object)
adapter.enqueue_at(job, timestamp)
adapter.enqueue_at(job, timestamp.to_f)
end
end

with "job with :wait option" do
let(:adapter) {subject.new(dispatcher)}
let(:job) {TestJob.new}
let(:wait) {0.second}

before do
dispatcher.queues["default"] = queue
job.set(wait:)
end
Copy link
Author

@davidalejandroaguilar davidalejandroaguilar Oct 26, 2025

Choose a reason for hiding this comment

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

The other spec tests that calling adapter.enqueue_at(job, timestamp.to_f) without explicitly setting scheduled_at on the job via set will successfully set scheduled_at.

This new spec tests that setting it on the job as you're supposed to (via set) will work.

We might not want to support the former test, but again, leaving it just in case we want to guarantee that.


it "can enqueue a job with :wait option" do
adapter.enqueue_at(job, job.scheduled_at.to_f)

Sync do
serialized_job = buffer.pop
expect(serialized_job).to have_keys(
"job_class" => be == "TestJob",
"queue_name" => be == "default",
"arguments" => be == [],
"scheduled_at" => be == job.scheduled_at.utc.iso8601(9),
)
end
end

it "successfully dispatches job through Sync wrapper" do
# This test verifies that the job gets dispatched successfully at a specific time
# The Sync wrapper is tested implicitly by the successful enqueueing
expect(dispatcher.queues["default"]).to be_a(Object)
adapter.enqueue_at(job, job.scheduled_at.to_f)
end
end

Expand Down