From 77bdbb5f41307f5566f41964479369521a616223 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Fri, 14 Oct 2016 09:15:51 +0900 Subject: add missing closing tag [ci skip] --- activejob/lib/active_job/exceptions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activejob/lib') diff --git a/activejob/lib/active_job/exceptions.rb b/activejob/lib/active_job/exceptions.rb index d236f03d53..c759068f9e 100644 --- a/activejob/lib/active_job/exceptions.rb +++ b/activejob/lib/active_job/exceptions.rb @@ -17,7 +17,7 @@ module ActiveJob # ==== Options # * :wait - Re-enqueues the job with a delay specified either in seconds (default: 3 seconds), # as a computing proc that the number of executions so far as an argument, or as a symbol reference of - # :exponentially_longer<>, which applies the wait algorithm of (executions ** 4) + 2 + # :exponentially_longer, which applies the wait algorithm of (executions ** 4) + 2 # (first wait 3s, then 18s, then 83s, etc) # * :attempts - Re-enqueues the job the specified number of times (default: 5 attempts) # * :queue - Re-enqueues the job on a different queue -- cgit v1.2.3 From 0d454d08061e183064c8148d313dbf05cab8c23b Mon Sep 17 00:00:00 2001 From: Gabi Stefanini Date: Wed, 19 Oct 2016 01:54:26 -0400 Subject: Add examples of queue_adapter and perform_enqueued jobs to API Docs. --- activejob/lib/active_job/test_helper.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'activejob/lib') diff --git a/activejob/lib/active_job/test_helper.rb b/activejob/lib/active_job/test_helper.rb index bbd2a0c06c..1a8b3375ae 100644 --- a/activejob/lib/active_job/test_helper.rb +++ b/activejob/lib/active_job/test_helper.rb @@ -269,6 +269,25 @@ module ActiveJob instantiate_job(matching_job) end + # Performs all enqueued jobs in the duration of the block. + # + # def test_perform_enqueued_jobs + # perform_enqueued_jobs do + # MyJob.perform_later(1, 2, 3) + # end + # assert_performed_jobs 1 + # end + # + # This method also supports filtering. If the +:only+ option is specified, + # then only the listed job(s) will be performed. + # + # def test_perform_enqueued_jobs_with_only + # perform_enqueued_jobs(only: MyJob) do + # MyJob.perform_later(1, 2, 3) # will be performed + # HelloJob.perform_later(1, 2, 3) # will not be perfomed + # end + # assert_performed_jobs 1 + # end def perform_enqueued_jobs(only: nil) old_perform_enqueued_jobs = queue_adapter.perform_enqueued_jobs old_perform_enqueued_at_jobs = queue_adapter.perform_enqueued_at_jobs @@ -286,6 +305,11 @@ module ActiveJob end end + # Accesses the queue_adapter set by ActiveJob::Base. + # + # def test_assert_job_has_custom_queue_adapter_set + # assert_instance_of CustomQueueAdapter, HelloJob.queue_adapter + # end def queue_adapter ActiveJob::Base.queue_adapter end -- cgit v1.2.3 From 7506f3390683fd1329e60385515c3c55b39ff1d5 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 27 Oct 2016 09:45:20 +0200 Subject: removes requires already present in active_support/rails --- activejob/lib/active_job/queue_adapter.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'activejob/lib') diff --git a/activejob/lib/active_job/queue_adapter.rb b/activejob/lib/active_job/queue_adapter.rb index 2e9f1e61be..bcc555d33e 100644 --- a/activejob/lib/active_job/queue_adapter.rb +++ b/activejob/lib/active_job/queue_adapter.rb @@ -1,5 +1,4 @@ require "active_job/queue_adapters/inline_adapter" -require "active_support/core_ext/class/attribute" require "active_support/core_ext/string/inflections" module ActiveJob -- cgit v1.2.3 From fe1f4b2ad56f010a4e9b93d547d63a15953d9dc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sat, 29 Oct 2016 01:05:58 -0200 Subject: Add more rubocop rules about whitespaces --- activejob/lib/active_job/configured_job.rb | 2 +- activejob/lib/active_job/core.rb | 2 +- activejob/lib/active_job/enqueuing.rb | 2 +- activejob/lib/active_job/exceptions.rb | 2 +- activejob/lib/active_job/queue_adapters/qu_adapter.rb | 2 +- activejob/lib/active_job/queue_name.rb | 2 +- activejob/lib/active_job/queue_priority.rb | 2 +- activejob/lib/active_job/railtie.rb | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) (limited to 'activejob/lib') diff --git a/activejob/lib/active_job/configured_job.rb b/activejob/lib/active_job/configured_job.rb index 979280b910..2ff31f2dae 100644 --- a/activejob/lib/active_job/configured_job.rb +++ b/activejob/lib/active_job/configured_job.rb @@ -1,6 +1,6 @@ module ActiveJob class ConfiguredJob #:nodoc: - def initialize(job_class, options={}) + def initialize(job_class, options = {}) @options = options @job_class = job_class end diff --git a/activejob/lib/active_job/core.rb b/activejob/lib/active_job/core.rb index a338061766..548ec89ee2 100644 --- a/activejob/lib/active_job/core.rb +++ b/activejob/lib/active_job/core.rb @@ -59,7 +59,7 @@ module ActiveJob # VideoJob.set(queue: :some_queue, wait: 5.minutes).perform_later(Video.last) # VideoJob.set(queue: :some_queue, wait_until: Time.now.tomorrow).perform_later(Video.last) # VideoJob.set(queue: :some_queue, wait: 5.minutes, priority: 10).perform_later(Video.last) - def set(options={}) + def set(options = {}) ConfiguredJob.new(self, options) end end diff --git a/activejob/lib/active_job/enqueuing.rb b/activejob/lib/active_job/enqueuing.rb index 18051a7d65..78eca1d2a1 100644 --- a/activejob/lib/active_job/enqueuing.rb +++ b/activejob/lib/active_job/enqueuing.rb @@ -39,7 +39,7 @@ module ActiveJob # my_job_instance.enqueue queue: :important # my_job_instance.enqueue wait_until: Date.tomorrow.midnight # my_job_instance.enqueue priority: 10 - def enqueue(options={}) + def enqueue(options = {}) 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.queue_name = self.class.queue_name_from_part(options[:queue]) if options[:queue] diff --git a/activejob/lib/active_job/exceptions.rb b/activejob/lib/active_job/exceptions.rb index c759068f9e..c1b5d35313 100644 --- a/activejob/lib/active_job/exceptions.rb +++ b/activejob/lib/active_job/exceptions.rb @@ -104,7 +104,7 @@ module ActiveJob def determine_delay(seconds_or_duration_or_algorithm) case seconds_or_duration_or_algorithm when :exponentially_longer - (executions ** 4) + 2 + (executions**4) + 2 when ActiveSupport::Duration duration = seconds_or_duration_or_algorithm duration.to_i diff --git a/activejob/lib/active_job/queue_adapters/qu_adapter.rb b/activejob/lib/active_job/queue_adapters/qu_adapter.rb index 20cc97ebc7..e8994533e4 100644 --- a/activejob/lib/active_job/queue_adapters/qu_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/qu_adapter.rb @@ -32,7 +32,7 @@ module ActiveJob class JobWrapper < Qu::Job #:nodoc: def initialize(job_data) - @job_data = job_data + @job_data = job_data end def perform diff --git a/activejob/lib/active_job/queue_name.rb b/activejob/lib/active_job/queue_name.rb index 143fac9888..352cf62424 100644 --- a/activejob/lib/active_job/queue_name.rb +++ b/activejob/lib/active_job/queue_name.rb @@ -16,7 +16,7 @@ module ActiveJob # post.to_feed! # end # end - def queue_as(part_name=nil, &block) + def queue_as(part_name = nil, &block) if block_given? self.queue_name = block else diff --git a/activejob/lib/active_job/queue_priority.rb b/activejob/lib/active_job/queue_priority.rb index a48e53b0ef..b02202fcc8 100644 --- a/activejob/lib/active_job/queue_priority.rb +++ b/activejob/lib/active_job/queue_priority.rb @@ -17,7 +17,7 @@ module ActiveJob # end # # Specify either an argument or a block. - def queue_with_priority(priority=nil, &block) + def queue_with_priority(priority = nil, &block) if block_given? self.priority = block else diff --git a/activejob/lib/active_job/railtie.rb b/activejob/lib/active_job/railtie.rb index e4198a40a5..4a8bf04d70 100644 --- a/activejob/lib/active_job/railtie.rb +++ b/activejob/lib/active_job/railtie.rb @@ -15,7 +15,7 @@ module ActiveJob options.queue_adapter ||= :async ActiveSupport.on_load(:active_job) do - options.each { |k,v| send("#{k}=", v) } + options.each { |k, v| send("#{k}=", v) } end end -- cgit v1.2.3 From c061236cc7e03ec6c8f71f1b166251cc63377417 Mon Sep 17 00:00:00 2001 From: Maxime Boisvert Date: Wed, 16 Nov 2016 15:41:30 -0500 Subject: Use named parameters instead of `assert_valid_keys` --- activejob/lib/active_job/test_helper.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'activejob/lib') diff --git a/activejob/lib/active_job/test_helper.rb b/activejob/lib/active_job/test_helper.rb index 1a8b3375ae..9e45c0da24 100644 --- a/activejob/lib/active_job/test_helper.rb +++ b/activejob/lib/active_job/test_helper.rb @@ -232,16 +232,16 @@ module ActiveJob # MyJob.set(wait_until: Date.tomorrow.noon).perform_later # end # end - def assert_enqueued_with(args = {}) + def assert_enqueued_with(job: nil, args: nil, at: nil, queue: nil) original_enqueued_jobs_count = enqueued_jobs.count - args.assert_valid_keys(:job, :args, :at, :queue) - serialized_args = serialize_args_for_assertion(args) + expected = { job: job, args: args, at: at, queue: queue }.compact + serialized_args = serialize_args_for_assertion(expected) yield in_block_jobs = enqueued_jobs.drop(original_enqueued_jobs_count) matching_job = in_block_jobs.find do |job| serialized_args.all? { |key, value| value == job[key] } end - assert matching_job, "No enqueued job found with #{args}" + assert matching_job, "No enqueued job found with #{expected}" instantiate_job(matching_job) end @@ -256,16 +256,16 @@ module ActiveJob # MyJob.set(wait_until: Date.tomorrow.noon).perform_later # end # end - def assert_performed_with(args = {}) + def assert_performed_with(job: nil, args: nil, at: nil, queue: nil) original_performed_jobs_count = performed_jobs.count - args.assert_valid_keys(:job, :args, :at, :queue) - serialized_args = serialize_args_for_assertion(args) + expected = { job: job, args: args, at: at, queue: queue }.compact + serialized_args = serialize_args_for_assertion(expected) perform_enqueued_jobs { yield } in_block_jobs = performed_jobs.drop(original_performed_jobs_count) matching_job = in_block_jobs.find do |job| serialized_args.all? { |key, value| value == job[key] } end - assert matching_job, "No performed job found with #{args}" + assert matching_job, "No performed job found with #{expected}" instantiate_job(matching_job) end -- cgit v1.2.3 From 5b825c55fea48c7c32921a62e4d10a99fdbe8a87 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Fri, 18 Nov 2016 18:20:48 +0900 Subject: remove Ruby warning from Active Job test helper methods This removes the following warnings. ``` /home/travis/build/rails/rails/activejob/lib/active_job/test_helper.rb:241: warning: shadowing outer local variable - job /home/travis/build/rails/rails/activejob/lib/active_job/test_helper.rb:265: warning: shadowing outer local variable - job ``` --- activejob/lib/active_job/test_helper.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'activejob/lib') diff --git a/activejob/lib/active_job/test_helper.rb b/activejob/lib/active_job/test_helper.rb index 9e45c0da24..e6334d14ea 100644 --- a/activejob/lib/active_job/test_helper.rb +++ b/activejob/lib/active_job/test_helper.rb @@ -238,8 +238,8 @@ module ActiveJob serialized_args = serialize_args_for_assertion(expected) yield in_block_jobs = enqueued_jobs.drop(original_enqueued_jobs_count) - matching_job = in_block_jobs.find do |job| - serialized_args.all? { |key, value| value == job[key] } + matching_job = in_block_jobs.find do |in_block_job| + serialized_args.all? { |key, value| value == in_block_job[key] } end assert matching_job, "No enqueued job found with #{expected}" instantiate_job(matching_job) @@ -262,8 +262,8 @@ module ActiveJob serialized_args = serialize_args_for_assertion(expected) perform_enqueued_jobs { yield } in_block_jobs = performed_jobs.drop(original_performed_jobs_count) - matching_job = in_block_jobs.find do |job| - serialized_args.all? { |key, value| value == job[key] } + matching_job = in_block_jobs.find do |in_block_job| + serialized_args.all? { |key, value| value == in_block_job[key] } end assert matching_job, "No performed job found with #{expected}" instantiate_job(matching_job) -- cgit v1.2.3 From 726b71cbb28b98aa6b96923029e745bfda7fc387 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sat, 24 Dec 2016 21:07:01 +0900 Subject: No need to nodoc private methods --- activejob/lib/active_job/test_helper.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'activejob/lib') diff --git a/activejob/lib/active_job/test_helper.rb b/activejob/lib/active_job/test_helper.rb index e6334d14ea..d01795f0c5 100644 --- a/activejob/lib/active_job/test_helper.rb +++ b/activejob/lib/active_job/test_helper.rb @@ -315,15 +315,15 @@ module ActiveJob end private - def clear_enqueued_jobs # :nodoc: + def clear_enqueued_jobs enqueued_jobs.clear end - def clear_performed_jobs # :nodoc: + def clear_performed_jobs performed_jobs.clear end - def enqueued_jobs_size(only: nil) # :nodoc: + def enqueued_jobs_size(only: nil) if only enqueued_jobs.count { |job| Array(only).include?(job.fetch(:job)) } else @@ -331,14 +331,14 @@ module ActiveJob end end - def serialize_args_for_assertion(args) # :nodoc: + def serialize_args_for_assertion(args) args.dup.tap do |serialized_args| serialized_args[:args] = ActiveJob::Arguments.serialize(serialized_args[:args]) if serialized_args[:args] serialized_args[:at] = serialized_args[:at].to_f if serialized_args[:at] end end - def instantiate_job(payload) # :nodoc: + def instantiate_job(payload) job = payload[:job].new(*payload[:args]) job.scheduled_at = Time.at(payload[:at]) if payload.key?(:at) job.queue_name = payload[:queue] -- cgit v1.2.3 From 102ee4055770813c847c95d3d6ff8741c33597d8 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Thu, 22 Dec 2016 19:03:42 +0900 Subject: Privatize unneededly protected method in Active Job --- activejob/lib/active_job/enqueuing.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activejob/lib') diff --git a/activejob/lib/active_job/enqueuing.rb b/activejob/lib/active_job/enqueuing.rb index 78eca1d2a1..c73117e7f3 100644 --- a/activejob/lib/active_job/enqueuing.rb +++ b/activejob/lib/active_job/enqueuing.rb @@ -18,8 +18,8 @@ module ActiveJob job_or_instantiate(*args).enqueue end - protected - def job_or_instantiate(*args) + private + def job_or_instantiate(*args) # :doc: args.first.is_a?(self) ? args.first : new(*args) end end -- cgit v1.2.3