diff --git a/changelog b/changelog index 7f47f308..0d405103 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +Unreleased +- Fixed a bug in the offset calculation of `.enqueue_at`. + Version 3.0.0rc - Improved signal handling diff --git a/lib/queue_classic/queue.rb b/lib/queue_classic/queue.rb index c1004609..581e91fb 100644 --- a/lib/queue_classic/queue.rb +++ b/lib/queue_classic/queue.rb @@ -47,7 +47,7 @@ def enqueue(method, *args) # and args argument must be in the form described in the documentation for # the #enqueue method. def enqueue_at(timestamp, method, *args) - offset = Time.at(timestamp) - Time.now + offset = Time.at(timestamp).to_i - Time.now.to_i enqueue_in(offset, method, *args) end diff --git a/test/queue_test.rb b/test/queue_test.rb index 3b80c497..c711381c 100644 --- a/test/queue_test.rb +++ b/test/queue_test.rb @@ -28,12 +28,14 @@ def test_lock_when_empty end def test_lock_with_future_job_with_enqueue_in + now = Time.now QC.enqueue_in(2, "Klass.method") assert_nil QC.lock sleep 2 job = QC.lock assert_equal("Klass.method", job[:method]) assert_equal([], job[:args]) + assert_equal((now + 2).to_i, job[:scheduled_at].to_i) end def test_lock_with_future_job_with_enqueue_at_with_a_time_object @@ -44,6 +46,7 @@ def test_lock_with_future_job_with_enqueue_at_with_a_time_object job = QC.lock assert_equal("Klass.method", job[:method]) assert_equal([], job[:args]) + assert_equal(future.to_i, job[:scheduled_at].to_i) end def test_lock_with_future_job_with_enqueue_at_with_a_float_timestamp