From fd69e0f0f3624bb8b4ce3586044f8132cc336896 Mon Sep 17 00:00:00 2001 From: Benjamin Wols Date: Sun, 21 May 2023 14:26:28 +0200 Subject: [PATCH] Fix scheduling job with wait --- Gemfile | 1 - .../active_job_options_parser.rb | 2 +- rails_async_methods.gemspec | 16 ++++++++-------- test/async_method_rails_test.rb | 5 ++--- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Gemfile b/Gemfile index 11517d3..8614383 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,6 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } # Specify your gem's dependencies in rails_async_methods.gemspec. gemspec -gem "pg" gem 'delayed_job_active_record' gem 'daemons' diff --git a/lib/rails_async_methods/active_job_options_parser.rb b/lib/rails_async_methods/active_job_options_parser.rb index 41a7662..720fc50 100644 --- a/lib/rails_async_methods/active_job_options_parser.rb +++ b/lib/rails_async_methods/active_job_options_parser.rb @@ -9,7 +9,7 @@ def initialize(opts={}) @prefix = method_prefix(opts[:prefix]) @queue = opts[:queue] @wait_until = opts[:wait_until].to_f if opts[:wait_until] - @wait = opts[:wait].seconds.from_now.to_f if opts[:wait] + @wait = opts[:wait].seconds.to_f if opts[:wait] @priority = opts[:priority].to_i if opts[:priority] @job = get_job_obj(opts[:job]) end diff --git a/rails_async_methods.gemspec b/rails_async_methods.gemspec index 2d6b8b8..4ab7732 100644 --- a/rails_async_methods.gemspec +++ b/rails_async_methods.gemspec @@ -5,9 +5,9 @@ Gem::Specification.new do |spec| spec.version = RailsAsyncMethods::VERSION spec.authors = ["benngarcia"] spec.email = ["beng4606@gmail.com"] - spec.homepage = "https://github.com/benngarcia/rails_async_methods" - spec.summary = "Quickly, create async callers and receivers for your rails methods, because y'know DRY." - spec.description = "Utilizes the ActiveJob api to provide async callers and receivers without duplicating code." + spec.homepage = "https://github.com/benngarcia/rails_async_methods" + spec.summary = "Quickly, create async callers and receivers for your rails methods, because y'know DRY." + spec.description = "Utilizes the ActiveJob api to provide async callers and receivers without duplicating code." spec.license = "MIT" spec.metadata["homepage_uri"] = spec.homepage @@ -17,10 +17,10 @@ Gem::Specification.new do |spec| Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"] end - spec.add_dependency "rails", ">= 7.0.2.4" spec.add_dependency "activesupport" - spec.add_development_dependency 'minitest' - spec.add_development_dependency 'pg' - spec.add_development_dependency 'pry' - spec.add_development_dependency 'sidekiq' + spec.add_dependency "rails", ">= 7.0.2.4" + spec.add_development_dependency "minitest" + spec.add_development_dependency "pg" + spec.add_development_dependency "pry" + spec.add_development_dependency "sidekiq" end diff --git a/test/async_method_rails_test.rb b/test/async_method_rails_test.rb index 7e5b247..46cb8d6 100644 --- a/test/async_method_rails_test.rb +++ b/test/async_method_rails_test.rb @@ -57,7 +57,7 @@ class RailsAsyncMethodsTest < ActiveSupport::TestCase ex = AsyncExample.create! dj = ex.async_method_with_diff_wait_time_and_priority - assert_in_epsilon dj.scheduled_at, 1.week.from_now.to_i, 60 + assert_in_delta dj.scheduled_at, 1.week.from_now.to_i, 60 assert_equal dj.priority, -10 end @@ -120,7 +120,7 @@ class RailsAsyncMethodsTest < ActiveSupport::TestCase assert_equal dj.queue_name, 'fast' assert_equal dj.class, ExampleCustomAsyncJob assert_not_nil ex.reload.testfield - assert_in_epsilon dj.scheduled_at, 1.week.from_now.to_i, 60 + assert_in_delta dj.scheduled_at, 1.week.from_now.to_i, 60 run_last assert_nil ex.reload.testfield end @@ -132,5 +132,4 @@ class RailsAsyncMethodsTest < ActiveSupport::TestCase assert_equal ex.reload.testfield, '[2, 3, 4]' end - end