From d694ea259c755924ba54e8e3783630ae3d737543 Mon Sep 17 00:00:00 2001 From: Logan Hasson Date: Wed, 20 Aug 2014 15:36:58 -0400 Subject: [ci skip] Fix Active Job grammar in api docs --- activejob/README.md | 2 +- activejob/lib/active_job/callbacks.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'activejob') diff --git a/activejob/README.md b/activejob/README.md index e48070bcfc..1f300fcf62 100644 --- a/activejob/README.md +++ b/activejob/README.md @@ -2,7 +2,7 @@ Active Job is a framework for declaring jobs and making them run on a variety of queueing backends. These jobs can be everything from regularly scheduled -clean-ups, billing charges, or mailings. Anything that can be chopped up into +clean-ups, to billing charges, to mailings. Anything that can be chopped up into small units of work and run in parallel, really. It also serves as the backend for ActionMailer's #deliver_later functionality diff --git a/activejob/lib/active_job/callbacks.rb b/activejob/lib/active_job/callbacks.rb index af92031bc9..8901fa77f2 100644 --- a/activejob/lib/active_job/callbacks.rb +++ b/activejob/lib/active_job/callbacks.rb @@ -3,7 +3,7 @@ require 'active_support/callbacks' module ActiveJob # = Active Job Callbacks # - # Active Job provides hooks during the lifecycle of a job. Callbacks allows you to trigger + # Active Job provides hooks during the lifecycle of a job. Callbacks allow you to trigger # logic during the lifecycle of a job. Available callbacks: # # * before_enqueue -- cgit v1.2.3 From 9b319a53fa880a2407c4836a25f3637d4891fad9 Mon Sep 17 00:00:00 2001 From: Nicholas Bruning Date: Thu, 21 Aug 2014 04:19:40 +0000 Subject: Added enqueue_at support for QueAdapter in ActiveJob * Added inline job runner for Que in test/support * Updated QueAdapter to support enqueue_at --- activejob/lib/active_job/queue_adapters/que_adapter.rb | 2 +- activejob/test/adapters/que.rb | 2 ++ activejob/test/support/que/inline.rb | 9 +++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 activejob/test/support/que/inline.rb (limited to 'activejob') diff --git a/activejob/lib/active_job/queue_adapters/que_adapter.rb b/activejob/lib/active_job/queue_adapters/que_adapter.rb index 0b87deb4e0..9c84c74f83 100644 --- a/activejob/lib/active_job/queue_adapters/que_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/que_adapter.rb @@ -9,7 +9,7 @@ module ActiveJob end def enqueue_at(job, timestamp, *args) - raise NotImplementedError + JobWrapper.enqueue job.name, *args, queue: job.queue_name, run_at: Time.at(timestamp) end end diff --git a/activejob/test/adapters/que.rb b/activejob/test/adapters/que.rb index 640061bf54..e6abc57457 100644 --- a/activejob/test/adapters/que.rb +++ b/activejob/test/adapters/que.rb @@ -1,2 +1,4 @@ +require 'support/que/inline' + ActiveJob::Base.queue_adapter = :que Que.mode = :sync diff --git a/activejob/test/support/que/inline.rb b/activejob/test/support/que/inline.rb new file mode 100644 index 0000000000..2e210acb6b --- /dev/null +++ b/activejob/test/support/que/inline.rb @@ -0,0 +1,9 @@ +require 'que' + +Que::Job.class_eval do + class << self; alias_method :original_enqueue, :enqueue; end + def self.enqueue(*args) + args.pop if args.last.is_a?(Hash) + self.run(*args) + end +end -- cgit v1.2.3 From a57f7b57976c74dd76c911f867b76197119546e6 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 21 Aug 2014 23:27:40 +0200 Subject: ActiveJob -> Active Job [ci skip] See http://guides.rubyonrails.org/api_documentation_guidelines.html#wording --- activejob/lib/active_job/gem_version.rb | 2 +- activejob/lib/active_job/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'activejob') diff --git a/activejob/lib/active_job/gem_version.rb b/activejob/lib/active_job/gem_version.rb index c166020b28..2545e09845 100644 --- a/activejob/lib/active_job/gem_version.rb +++ b/activejob/lib/active_job/gem_version.rb @@ -1,5 +1,5 @@ module ActiveJob - # Returns the version of the currently loaded ActiveJob as a Gem::Version + # Returns the version of the currently loaded Active Job as a Gem::Version def self.gem_version Gem::Version.new VERSION::STRING end diff --git a/activejob/lib/active_job/version.rb b/activejob/lib/active_job/version.rb index 7e646fa3c4..971ba9fe0c 100644 --- a/activejob/lib/active_job/version.rb +++ b/activejob/lib/active_job/version.rb @@ -1,7 +1,7 @@ require_relative 'gem_version' module ActiveJob - # Returns the version of the currently loaded ActiveJob as a Gem::Version + # Returns the version of the currently loaded Active Job as a Gem::Version def self.version gem_version end -- cgit v1.2.3 From fb740239dc0ea7e543388f057e205c68b67a449c Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Fri, 22 Aug 2014 17:47:13 +0800 Subject: Pass logging message through block. This follows the good practice listed on http://guides.rubyonrails.org/debugging_rails_applications.html#impact-of-logs-on-performance --- activejob/lib/active_job/logging.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'activejob') diff --git a/activejob/lib/active_job/logging.rb b/activejob/lib/active_job/logging.rb index d9e544acf5..ae098a80f3 100644 --- a/activejob/lib/active_job/logging.rb +++ b/activejob/lib/active_job/logging.rb @@ -52,19 +52,19 @@ module ActiveJob class LogSubscriber < ActiveSupport::LogSubscriber def enqueue(event) - info "Enqueued #{event.payload[:job].name} (Job ID: #{event.payload[:job_id]}) to #{queue_name(event)}" + args_info(event) + info { "Enqueued #{event.payload[:job].name} (Job ID: #{event.payload[:job_id]}) to #{queue_name(event)}" + args_info(event) } end def enqueue_at(event) - info "Enqueued #{event.payload[:job].name} (Job ID: #{event.payload[:job_id]}) to #{queue_name(event)} at #{enqueued_at(event)}" + args_info(event) + info { "Enqueued #{event.payload[:job].name} (Job ID: #{event.payload[:job_id]}) to #{queue_name(event)} at #{enqueued_at(event)}" + args_info(event) } end def perform_start(event) - info "Performing #{event.payload[:job].name} from #{queue_name(event)}" + args_info(event) + info { "Performing #{event.payload[:job].name} from #{queue_name(event)}" + args_info(event) } end def perform(event) - info "Performed #{event.payload[:job].name} from #{queue_name(event)} in #{event.duration.round(2).to_s}ms" + info { "Performed #{event.payload[:job].name} from #{queue_name(event)} in #{event.duration.round(2).to_s}ms" } end private -- cgit v1.2.3 From e084d5bd7aaa113f29b4ea8d0f2305daeae33826 Mon Sep 17 00:00:00 2001 From: Cristian Bica Date: Fri, 22 Aug 2014 17:44:48 +0300 Subject: Implemented enqueue_at for ActiveJob's Backburner adapter --- activejob/lib/active_job/queue_adapters/backburner_adapter.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activejob') diff --git a/activejob/lib/active_job/queue_adapters/backburner_adapter.rb b/activejob/lib/active_job/queue_adapters/backburner_adapter.rb index 6fe2d4eb53..8d34155645 100644 --- a/activejob/lib/active_job/queue_adapters/backburner_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/backburner_adapter.rb @@ -9,7 +9,8 @@ module ActiveJob end def enqueue_at(job, timestamp, *args) - raise NotImplementedError + delay = Time.current.to_f - timestamp + Backburner::Worker.enqueue JobWrapper, [ job.name, *args ], queue: job.queue_name, delay: delay end end -- cgit v1.2.3 From e63a02ccfbbdc0aeefd57617c835a2adc8588dd3 Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Fri, 22 Aug 2014 19:30:36 +0000 Subject: [ActiveJob] Add hook for test_framework and test templates --- activejob/lib/rails/generators/job/job_generator.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'activejob') diff --git a/activejob/lib/rails/generators/job/job_generator.rb b/activejob/lib/rails/generators/job/job_generator.rb index 78a9c27606..979ffcb748 100644 --- a/activejob/lib/rails/generators/job/job_generator.rb +++ b/activejob/lib/rails/generators/job/job_generator.rb @@ -7,12 +7,14 @@ module Rails class_option :queue, type: :string, default: 'default', desc: 'The queue name for the generated job' + check_class_collision suffix: 'Job' + + hook_for :test_framework + def self.default_generator_root File.dirname(__FILE__) end - check_class_collision suffix: 'Job' - def create_job_file template 'job.rb', File.join('app/jobs', class_path, "#{file_name}_job.rb") end -- cgit v1.2.3 From 23329d33d45c7388d33c6080820927b96fb34890 Mon Sep 17 00:00:00 2001 From: Cristian Bica Date: Sat, 23 Aug 2014 14:19:44 +0300 Subject: Raise ActiveJob::SerializationError when cannot serialize job arguments --- activejob/lib/active_job/arguments.rb | 15 +++++++++++++-- activejob/test/cases/parameters_test.rb | 6 +++--- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'activejob') diff --git a/activejob/lib/active_job/arguments.rb b/activejob/lib/active_job/arguments.rb index 369e716912..ccee4ab35b 100644 --- a/activejob/lib/active_job/arguments.rb +++ b/activejob/lib/active_job/arguments.rb @@ -1,4 +1,7 @@ module ActiveJob + # Raised when an exception is raised during job arguments deserialization. + # + # Wraps the original exception raised as +original_exception+. class DeserializationError < StandardError attr_reader :original_exception @@ -9,6 +12,14 @@ module ActiveJob end end + # Raised when an unsupporter argument type is being set as job argument. We + # currently support NilClass, Fixnum, Float, String, TrueClass, FalseClass, + # Bignum and object that can be represented as GlobalIDs (ex: Active Record). + # Also raised if you set the key for a Hash something else than a string or + # a symbol. + class SerializationError < ArgumentError + end + module Arguments extend self TYPE_WHITELIST = [ NilClass, Fixnum, Float, String, TrueClass, FalseClass, Bignum ] @@ -33,7 +44,7 @@ module ActiveJob when Hash Hash[ argument.map { |key, value| [ serialize_hash_key(key), serialize_argument(value) ] } ] else - raise "Unsupported argument type: #{argument.class.name}" + raise SerializationError.new("Unsupported argument type: #{argument.class.name}") end end @@ -55,7 +66,7 @@ module ActiveJob when String, Symbol key.to_s else - raise "Unsupported hash key type: #{key.class.name}" + raise SerializationError.new("Unsupported hash key type: #{key.class.name}") end end end diff --git a/activejob/test/cases/parameters_test.rb b/activejob/test/cases/parameters_test.rb index 76e8a8059a..78853c51e1 100644 --- a/activejob/test/cases/parameters_test.rb +++ b/activejob/test/cases/parameters_test.rb @@ -19,7 +19,7 @@ class ParameterSerializationTest < ActiveSupport::TestCase assert_equal [ [ 1 ] ], ActiveJob::Arguments.serialize([ [ 1 ] ]) assert_equal [ 1_000_000_000_000_000_000_000 ], ActiveJob::Arguments.serialize([ 1_000_000_000_000_000_000_000 ]) - err = assert_raises RuntimeError do + err = assert_raises ActiveJob::SerializationError do ActiveJob::Arguments.serialize([ 1, self ]) end assert_equal "Unsupported argument type: #{self.class.name}", err.message @@ -31,14 +31,14 @@ class ParameterSerializationTest < ActiveSupport::TestCase end test 'should dive deep into arrays or hashes and raise exception on complex objects' do - err = assert_raises RuntimeError do + err = assert_raises ActiveJob::SerializationError do ActiveJob::Arguments.serialize([ 1, [self] ]) end assert_equal "Unsupported argument type: #{self.class.name}", err.message end test 'shoud dive deep into hashes and allow raise exception on not string/symbol keys' do - err = assert_raises RuntimeError do + err = assert_raises ActiveJob::SerializationError do ActiveJob::Arguments.serialize([ [ { 1 => 2 } ] ]) end assert_equal "Unsupported hash key type: Fixnum", err.message -- cgit v1.2.3 From f3b8a0d375fe441d70b9c77bd9c20347c71a70cb Mon Sep 17 00:00:00 2001 From: Robin Dupret Date: Sun, 24 Aug 2014 18:33:59 +0200 Subject: Fix a few typos [ci skip] --- activejob/lib/active_job/arguments.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activejob') diff --git a/activejob/lib/active_job/arguments.rb b/activejob/lib/active_job/arguments.rb index ccee4ab35b..e54f4afbc7 100644 --- a/activejob/lib/active_job/arguments.rb +++ b/activejob/lib/active_job/arguments.rb @@ -12,7 +12,7 @@ module ActiveJob end end - # Raised when an unsupporter argument type is being set as job argument. We + # Raised when an unsupported argument type is being set as job argument. We # currently support NilClass, Fixnum, Float, String, TrueClass, FalseClass, # Bignum and object that can be represented as GlobalIDs (ex: Active Record). # Also raised if you set the key for a Hash something else than a string or -- cgit v1.2.3 From 8fc99194cab78cabe77ae4dd21764ab8200df97e Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Sun, 24 Aug 2014 22:16:48 +0000 Subject: [ActiveJob] Add activesupport as dependency [ci skip] --- activejob/activejob.gemspec | 1 + 1 file changed, 1 insertion(+) (limited to 'activejob') diff --git a/activejob/activejob.gemspec b/activejob/activejob.gemspec index c74daa5045..9944b2a1bd 100644 --- a/activejob/activejob.gemspec +++ b/activejob/activejob.gemspec @@ -18,5 +18,6 @@ Gem::Specification.new do |s| s.files = Dir['CHANGELOG.md', 'MIT-LICENSE', 'README.md', 'lib/**/*'] s.require_path = 'lib' + s.add_dependency 'activesupport', version s.add_dependency 'globalid', '>= 0.2.3' end -- cgit v1.2.3 From 7e99855dee8db2bf155a502fb3110f47487fcbdd Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Tue, 26 Aug 2014 12:22:59 +0000 Subject: [ActiveJob] Autoload adapters --- activejob/lib/active_job.rb | 3 ++- activejob/lib/active_job/queue_adapter.rb | 1 - activejob/lib/active_job/queue_adapters.rb | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 activejob/lib/active_job/queue_adapters.rb (limited to 'activejob') diff --git a/activejob/lib/active_job.rb b/activejob/lib/active_job.rb index ef92406725..29123170b8 100644 --- a/activejob/lib/active_job.rb +++ b/activejob/lib/active_job.rb @@ -30,4 +30,5 @@ module ActiveJob extend ActiveSupport::Autoload autoload :Base -end \ No newline at end of file + autoload :QueueAdapters +end diff --git a/activejob/lib/active_job/queue_adapter.rb b/activejob/lib/active_job/queue_adapter.rb index 8f2f8b86ea..13c23abce4 100644 --- a/activejob/lib/active_job/queue_adapter.rb +++ b/activejob/lib/active_job/queue_adapter.rb @@ -17,7 +17,6 @@ module ActiveJob private def load_adapter(name) - require "active_job/queue_adapters/#{name}_adapter" "ActiveJob::QueueAdapters::#{name.to_s.camelize}Adapter".constantize end end diff --git a/activejob/lib/active_job/queue_adapters.rb b/activejob/lib/active_job/queue_adapters.rb new file mode 100644 index 0000000000..007068ff0a --- /dev/null +++ b/activejob/lib/active_job/queue_adapters.rb @@ -0,0 +1,16 @@ +module ActiveJob + module QueueAdapters + extend ActiveSupport::Autoload + + autoload :InlineAdapter + autoload :BackburnerAdapter + autoload :DelayedJobAdapter + autoload :QuAdapter + autoload :QueAdapter + autoload :QueueClassicAdapter + autoload :ResqueAdapter + autoload :SidekiqAdapter + autoload :SneakersAdapter + autoload :SuckerPunchAdapter + end +end -- cgit v1.2.3 From d56caea4269abbc6d13f63de40e3b686b13a066f Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Fri, 29 Aug 2014 08:28:07 +0000 Subject: [ActiveJob] extract JobBuffer from helper --- activejob/test/helper.rb | 20 -------------------- activejob/test/jobs/gid_job.rb | 2 ++ activejob/test/jobs/hello_job.rb | 2 ++ activejob/test/jobs/rescue_job.rb | 2 ++ activejob/test/support/job_buffer.rb | 19 +++++++++++++++++++ 5 files changed, 25 insertions(+), 20 deletions(-) create mode 100644 activejob/test/support/job_buffer.rb (limited to 'activejob') diff --git a/activejob/test/helper.rb b/activejob/test/helper.rb index ca67700273..a56b35da12 100644 --- a/activejob/test/helper.rb +++ b/activejob/test/helper.rb @@ -28,23 +28,3 @@ require "adapters/#{@adapter}" require 'active_support/testing/autorun' ActiveJob::Base.logger.level = Logger::DEBUG - -module JobBuffer - class << self - def clear - @buffer = [] - end - - def add(value) - @buffer << value - end - - def values - @buffer - end - - def last_value - @buffer.last - end - end -end diff --git a/activejob/test/jobs/gid_job.rb b/activejob/test/jobs/gid_job.rb index 35c2366ec4..e485bfa2dd 100644 --- a/activejob/test/jobs/gid_job.rb +++ b/activejob/test/jobs/gid_job.rb @@ -1,3 +1,5 @@ +require_relative '../support/job_buffer' + class GidJob < ActiveJob::Base def perform(person) JobBuffer.add("Person with ID: #{person.id}") diff --git a/activejob/test/jobs/hello_job.rb b/activejob/test/jobs/hello_job.rb index 4c6256af0d..022fa58e4a 100644 --- a/activejob/test/jobs/hello_job.rb +++ b/activejob/test/jobs/hello_job.rb @@ -1,3 +1,5 @@ +require_relative '../support/job_buffer' + class HelloJob < ActiveJob::Base def perform(greeter = "David") JobBuffer.add("#{greeter} says hello") diff --git a/activejob/test/jobs/rescue_job.rb b/activejob/test/jobs/rescue_job.rb index e9cb37d1c4..6b6e74e9d0 100644 --- a/activejob/test/jobs/rescue_job.rb +++ b/activejob/test/jobs/rescue_job.rb @@ -1,3 +1,5 @@ +require_relative '../support/job_buffer' + class RescueJob < ActiveJob::Base class OtherError < StandardError; end diff --git a/activejob/test/support/job_buffer.rb b/activejob/test/support/job_buffer.rb new file mode 100644 index 0000000000..620cb5288d --- /dev/null +++ b/activejob/test/support/job_buffer.rb @@ -0,0 +1,19 @@ +module JobBuffer + class << self + def clear + values.clear + end + + def add(value) + values << value + end + + def values + @values ||= [] + end + + def last_value + values.last + end + end +end -- cgit v1.2.3 From 38d6c722b23bae2eeb82a63fc1e78c0937bed17a Mon Sep 17 00:00:00 2001 From: Robin Dupret Date: Fri, 29 Aug 2014 12:36:45 +0200 Subject: Some documentation fixes [ci skip] --- activejob/lib/active_job/callbacks.rb | 4 ++-- activejob/lib/active_job/gem_version.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'activejob') diff --git a/activejob/lib/active_job/callbacks.rb b/activejob/lib/active_job/callbacks.rb index 8901fa77f2..cafa3438c0 100644 --- a/activejob/lib/active_job/callbacks.rb +++ b/activejob/lib/active_job/callbacks.rb @@ -3,8 +3,8 @@ require 'active_support/callbacks' module ActiveJob # = Active Job Callbacks # - # Active Job provides hooks during the lifecycle of a job. Callbacks allow you to trigger - # logic during the lifecycle of a job. Available callbacks: + # Active Job provides hooks during the lifecycle of a job. Callbacks allow you + # to trigger logic during the lifecycle of a job. Available callbacks are: # # * before_enqueue # * around_enqueue diff --git a/activejob/lib/active_job/gem_version.rb b/activejob/lib/active_job/gem_version.rb index 2545e09845..c166020b28 100644 --- a/activejob/lib/active_job/gem_version.rb +++ b/activejob/lib/active_job/gem_version.rb @@ -1,5 +1,5 @@ module ActiveJob - # Returns the version of the currently loaded Active Job as a Gem::Version + # Returns the version of the currently loaded ActiveJob as a Gem::Version def self.gem_version Gem::Version.new VERSION::STRING end -- cgit v1.2.3 From 1da209fa9bb83ca7ee8a9a1722e124877e839936 Mon Sep 17 00:00:00 2001 From: Robin Dupret Date: Wed, 27 Aug 2014 19:47:39 +0200 Subject: Avoid skipping Sidekiq tests on Rubinius Now that Travis provides support for Rubinius 2.2.10, we can run the Sidekiq tests against this version. --- activejob/test/helper.rb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'activejob') diff --git a/activejob/test/helper.rb b/activejob/test/helper.rb index a56b35da12..85094387ef 100644 --- a/activejob/test/helper.rb +++ b/activejob/test/helper.rb @@ -10,18 +10,12 @@ def sidekiq? @adapter == 'sidekiq' end -def rubinius? - RUBY_ENGINE == 'rbx' -end - def ruby_193? RUBY_VERSION == '1.9.3' && RUBY_ENGINE != 'java' end -#Sidekiq don't work with MRI 1.9.3 -#Travis uses rbx 2.6 which don't support unicode characters in methods. -#Remove the check when Travis change to rbx 2.7+ -exit if sidekiq? && (ruby_193? || rubinius?) +# Sidekiq doesn't work with MRI 1.9.3 +exit if sidekiq? && ruby_193? require "adapters/#{@adapter}" -- cgit v1.2.3 From 02b63a5f9e441a02b6e22ad8b3f8e66c10a996fc Mon Sep 17 00:00:00 2001 From: Cristian Bica Date: Sat, 30 Aug 2014 00:04:01 +0300 Subject: Fixed Active Job Backburner adapter --- activejob/lib/active_job/queue_adapters/backburner_adapter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activejob') diff --git a/activejob/lib/active_job/queue_adapters/backburner_adapter.rb b/activejob/lib/active_job/queue_adapters/backburner_adapter.rb index 8d34155645..8ebee36e45 100644 --- a/activejob/lib/active_job/queue_adapters/backburner_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/backburner_adapter.rb @@ -9,7 +9,7 @@ module ActiveJob end def enqueue_at(job, timestamp, *args) - delay = Time.current.to_f - timestamp + delay = timestamp - Time.current.to_f Backburner::Worker.enqueue JobWrapper, [ job.name, *args ], queue: job.queue_name, delay: delay end end -- cgit v1.2.3