diff options
Diffstat (limited to 'activejob/lib/active_job')
-rw-r--r-- | activejob/lib/active_job/base.rb | 20 | ||||
-rw-r--r-- | activejob/lib/active_job/callbacks.rb | 4 | ||||
-rw-r--r-- | activejob/lib/active_job/core.rb | 1 | ||||
-rw-r--r-- | activejob/lib/active_job/enqueuing.rb | 2 | ||||
-rw-r--r-- | activejob/lib/active_job/execution.rb | 2 | ||||
-rw-r--r-- | activejob/lib/active_job/logging.rb | 15 | ||||
-rw-r--r-- | activejob/lib/active_job/queue_adapter.rb | 19 | ||||
-rw-r--r-- | activejob/lib/active_job/queue_name.rb | 11 | ||||
-rw-r--r-- | activejob/lib/active_job/queue_priority.rb | 6 |
9 files changed, 49 insertions, 31 deletions
diff --git a/activejob/lib/active_job/base.rb b/activejob/lib/active_job/base.rb index 18e8641e50..af76d019c4 100644 --- a/activejob/lib/active_job/base.rb +++ b/activejob/lib/active_job/base.rb @@ -1,13 +1,13 @@ -require "active_job/core" -require "active_job/queue_adapter" -require "active_job/queue_name" -require "active_job/queue_priority" -require "active_job/enqueuing" -require "active_job/execution" -require "active_job/callbacks" -require "active_job/exceptions" -require "active_job/logging" -require "active_job/translation" +require_relative "core" +require_relative "queue_adapter" +require_relative "queue_name" +require_relative "queue_priority" +require_relative "enqueuing" +require_relative "execution" +require_relative "callbacks" +require_relative "exceptions" +require_relative "logging" +require_relative "translation" module ActiveJob #:nodoc: # = Active Job diff --git a/activejob/lib/active_job/callbacks.rb b/activejob/lib/active_job/callbacks.rb index d5b17de8b5..9aebc880a5 100644 --- a/activejob/lib/active_job/callbacks.rb +++ b/activejob/lib/active_job/callbacks.rb @@ -4,7 +4,7 @@ module ActiveJob # = Active Job Callbacks # # Active Job provides hooks during the life cycle of a job. Callbacks allow you - # to trigger logic during the life cycle of a job. Available callbacks are: + # to trigger logic during this cycle. Available callbacks are: # # * <tt>before_enqueue</tt> # * <tt>around_enqueue</tt> @@ -13,6 +13,8 @@ module ActiveJob # * <tt>around_perform</tt> # * <tt>after_perform</tt> # + # NOTE: Calling the same callback multiple times will overwrite previous callback definitions. + # module Callbacks extend ActiveSupport::Concern include ActiveSupport::Callbacks diff --git a/activejob/lib/active_job/core.rb b/activejob/lib/active_job/core.rb index 548ec89ee2..e3e63f227e 100644 --- a/activejob/lib/active_job/core.rb +++ b/activejob/lib/active_job/core.rb @@ -80,6 +80,7 @@ module ActiveJob { "job_class" => self.class.name, "job_id" => job_id, + "provider_job_id" => provider_job_id, "queue_name" => queue_name, "priority" => priority, "arguments" => serialize_arguments(arguments), diff --git a/activejob/lib/active_job/enqueuing.rb b/activejob/lib/active_job/enqueuing.rb index c73117e7f3..994645c62a 100644 --- a/activejob/lib/active_job/enqueuing.rb +++ b/activejob/lib/active_job/enqueuing.rb @@ -1,4 +1,4 @@ -require "active_job/arguments" +require_relative "arguments" module ActiveJob # Provides behavior for enqueuing jobs. diff --git a/activejob/lib/active_job/execution.rb b/activejob/lib/active_job/execution.rb index 94d30c8eaf..69486676d1 100644 --- a/activejob/lib/active_job/execution.rb +++ b/activejob/lib/active_job/execution.rb @@ -1,5 +1,5 @@ require "active_support/rescuable" -require "active_job/arguments" +require_relative "arguments" module ActiveJob module Execution diff --git a/activejob/lib/active_job/logging.rb b/activejob/lib/active_job/logging.rb index d7e2cd03e3..ddc4915fd3 100644 --- a/activejob/lib/active_job/logging.rb +++ b/activejob/lib/active_job/logging.rb @@ -8,7 +8,7 @@ module ActiveJob extend ActiveSupport::Concern included do - cattr_accessor(:logger) { ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) } + cattr_accessor :logger, default: ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) around_enqueue do |_, block, _| tag_logger do @@ -74,9 +74,16 @@ module ActiveJob end def perform(event) - info do - job = event.payload[:job] - "Performed #{job.class.name} (Job ID: #{job.job_id}) from #{queue_name(event)} in #{event.duration.round(2)}ms" + job = event.payload[:job] + ex = event.payload[:exception_object] + if ex + error do + "Error performing #{job.class.name} (Job ID: #{job.job_id}) from #{queue_name(event)} in #{event.duration.round(2)}ms: #{ex.class} (#{ex.message}):\n" + Array(ex.backtrace).join("\n") + end + else + info do + "Performed #{job.class.name} (Job ID: #{job.job_id}) from #{queue_name(event)} in #{event.duration.round(2)}ms" + end end end diff --git a/activejob/lib/active_job/queue_adapter.rb b/activejob/lib/active_job/queue_adapter.rb index 9dae80ffc2..b22d8b8347 100644 --- a/activejob/lib/active_job/queue_adapter.rb +++ b/activejob/lib/active_job/queue_adapter.rb @@ -7,6 +7,7 @@ module ActiveJob extend ActiveSupport::Concern included do + class_attribute :_queue_adapter_name, instance_accessor: false, instance_predicate: false class_attribute :_queue_adapter, instance_accessor: false, instance_predicate: false self.queue_adapter = :async end @@ -19,11 +20,15 @@ module ActiveJob _queue_adapter end + def queue_adapter_name + _queue_adapter_name + end + # Specify the backend queue provider. The default queue adapter # is the +:async+ queue. See QueueAdapters for more # information. def queue_adapter=(name_or_adapter_or_class) - self._queue_adapter = interpret_adapter(name_or_adapter_or_class) + interpret_adapter(name_or_adapter_or_class) end private @@ -31,16 +36,24 @@ module ActiveJob def interpret_adapter(name_or_adapter_or_class) case name_or_adapter_or_class when Symbol, String - ActiveJob::QueueAdapters.lookup(name_or_adapter_or_class).new + assign_adapter(name_or_adapter_or_class.to_s, + ActiveJob::QueueAdapters.lookup(name_or_adapter_or_class).new) else if queue_adapter?(name_or_adapter_or_class) - name_or_adapter_or_class + adapter_name = "#{name_or_adapter_or_class.class.name.demodulize.remove('Adapter').underscore}" + assign_adapter(adapter_name, + name_or_adapter_or_class) else raise ArgumentError end end end + def assign_adapter(adapter_name, queue_adapter) + self._queue_adapter_name = adapter_name + self._queue_adapter = queue_adapter + end + QUEUE_ADAPTER_METHODS = [:enqueue, :enqueue_at].freeze def queue_adapter?(object) diff --git a/activejob/lib/active_job/queue_name.rb b/activejob/lib/active_job/queue_name.rb index 352cf62424..6f521a1c1a 100644 --- a/activejob/lib/active_job/queue_name.rb +++ b/activejob/lib/active_job/queue_name.rb @@ -4,8 +4,8 @@ module ActiveJob # Includes the ability to override the default queue name and prefix. module ClassMethods - mattr_accessor(:queue_name_prefix) - mattr_accessor(:default_queue_name) { "default" } + mattr_accessor :queue_name_prefix + mattr_accessor :default_queue_name, default: "default" # Specifies the name of the queue to process the job on. # @@ -32,11 +32,8 @@ module ActiveJob end included do - class_attribute :queue_name, instance_accessor: false - class_attribute :queue_name_delimiter, instance_accessor: false - - self.queue_name = default_queue_name - self.queue_name_delimiter = "_" # set default delimiter to '_' + class_attribute :queue_name, instance_accessor: false, default: default_queue_name + class_attribute :queue_name_delimiter, instance_accessor: false, default: "_" end # Returns the name of the queue the job will be run on. diff --git a/activejob/lib/active_job/queue_priority.rb b/activejob/lib/active_job/queue_priority.rb index b02202fcc8..399d7a135a 100644 --- a/activejob/lib/active_job/queue_priority.rb +++ b/activejob/lib/active_job/queue_priority.rb @@ -4,7 +4,7 @@ module ActiveJob # Includes the ability to override the default queue priority. module ClassMethods - mattr_accessor(:default_priority) + mattr_accessor :default_priority # Specifies the priority of the queue to create the job with. # @@ -27,9 +27,7 @@ module ActiveJob end included do - class_attribute :priority, instance_accessor: false - - self.priority = default_priority + class_attribute :priority, instance_accessor: false, default: default_priority end # Returns the priority that the job will be created with |