Skip to content

Commit

Permalink
Remove to_f in set method to prevent error
Browse files Browse the repository at this point in the history
This change prevents a `NoMethodError` when retrying jobs or scheduling
jobs with `set(wait: ...)` for adapters like GoodJob and Solid Queue.
  • Loading branch information
ahacop committed Sep 23, 2024
1 parent f49e6b3 commit dc546cb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/acidic_job/mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def idempotency_key

# Configures the job with the given options.
def set(options = {}) # :nodoc:
self.scheduled_at = options[:wait].seconds.from_now.to_f if options[:wait]
self.scheduled_at = options[:wait_until].to_f if options[:wait_until]
self.scheduled_at = options[:wait].seconds.from_now if options[:wait]
self.scheduled_at = options[:wait_until] if options[:wait_until]
self.queue_name = self.class.queue_name_from_part(options[:queue]) if options[:queue]
self.priority = options[:priority].to_i if options[:priority]

Expand Down
15 changes: 15 additions & 0 deletions test/cases/active_job/basics_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Cases
module ActiveJob
class Basics < ActiveSupport::TestCase
include ::ActiveJob::TestHelper
include ActiveSupport::Testing::TimeHelpers

def before_setup
super()
Expand Down Expand Up @@ -384,6 +385,20 @@ def do_something
assert_equal "FINISHED", run.recovery_point
assert_equal 1, Performance.performances
end

test "job can be scheduled to be run in the future" do
class FutureJob < ::AcidicJob::Base
def perform; end
end

freeze_time

FutureJob.set(wait: 1.minute).perform_later
FutureJob.set(wait_until: 2.minutes.from_now).perform_later

assert_equal 1.minute.from_now, enqueued_jobs[0][:at]
assert_equal 2.minutes.from_now, enqueued_jobs[1][:at]
end
end
end
end
Expand Down

0 comments on commit dc546cb

Please sign in to comment.