diff options
Diffstat (limited to 'lib/active_job')
-rw-r--r-- | lib/active_job/base.rb | 4 | ||||
-rw-r--r-- | lib/active_job/enqueuing.rb | 1 | ||||
-rw-r--r-- | lib/active_job/log_subscriber.rb | 18 | ||||
-rw-r--r-- | lib/active_job/logging.rb | 7 |
4 files changed, 29 insertions, 1 deletions
diff --git a/lib/active_job/base.rb b/lib/active_job/base.rb index 77b929d4af..3d16f38275 100644 --- a/lib/active_job/base.rb +++ b/lib/active_job/base.rb @@ -1,11 +1,13 @@ require 'active_job/queue_adapter' require 'active_job/queue_name' require 'active_job/enqueuing' +require 'active_job/logging' module ActiveJob class Base extend QueueAdapter extend QueueName extend Enqueuing + extend Logging end -end
\ No newline at end of file +end diff --git a/lib/active_job/enqueuing.rb b/lib/active_job/enqueuing.rb index 324385216e..46f703481a 100644 --- a/lib/active_job/enqueuing.rb +++ b/lib/active_job/enqueuing.rb @@ -11,6 +11,7 @@ module ActiveJob # The return value is adapter-specific and may change in a future # ActiveJob release. def enqueue(*args) + ActiveSupport::Notifications.instrument "enqueue.active_job", adapter: queue_adapter, job: self, params: args queue_adapter.queue self, *Parameters.serialize(args) end end diff --git a/lib/active_job/log_subscriber.rb b/lib/active_job/log_subscriber.rb new file mode 100644 index 0000000000..31c61a6068 --- /dev/null +++ b/lib/active_job/log_subscriber.rb @@ -0,0 +1,18 @@ +module ActiveJob + class LogSubscriber < ActiveSupport::LogSubscriber + def enqueue(event) + payload = event.payload + params = payload[:params] + adapter = payload[:adapter] + job = payload[:job] + + info "ActiveJob enqueued to #{adapter.name.demodulize} job #{job.name}: #{params.inspect}" + end + + def logger + ActiveJob::Base.logger + end + end +end + +ActiveJob::LogSubscriber.attach_to :active_job diff --git a/lib/active_job/logging.rb b/lib/active_job/logging.rb new file mode 100644 index 0000000000..0e994a8f54 --- /dev/null +++ b/lib/active_job/logging.rb @@ -0,0 +1,7 @@ +require 'active_job/log_subscriber' + +module ActiveJob + module Logging + mattr_accessor(:logger) { ActiveSupport::Logger.new(STDOUT) } + end +end |