From dc546cb7d6a846498b4c16654ce53c90947a3e89 Mon Sep 17 00:00:00 2001 From: Ara Hacopian Date: Thu, 19 Sep 2024 10:51:57 +0200 Subject: [PATCH] Remove `to_f` in `set` method to prevent error This change prevents a `NoMethodError` when retrying jobs or scheduling jobs with `set(wait: ...)` for adapters like GoodJob and Solid Queue. --- lib/acidic_job/mixin.rb | 4 ++-- test/cases/active_job/basics_test.rb | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/acidic_job/mixin.rb b/lib/acidic_job/mixin.rb index e269429..b8d1d92 100644 --- a/lib/acidic_job/mixin.rb +++ b/lib/acidic_job/mixin.rb @@ -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] diff --git a/test/cases/active_job/basics_test.rb b/test/cases/active_job/basics_test.rb index 5580f9d..4b4f421 100644 --- a/test/cases/active_job/basics_test.rb +++ b/test/cases/active_job/basics_test.rb @@ -8,6 +8,7 @@ module Cases module ActiveJob class Basics < ActiveSupport::TestCase include ::ActiveJob::TestHelper + include ActiveSupport::Testing::TimeHelpers def before_setup super() @@ -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