diff options
author | Cristian Bica <cristian.bica@gmail.com> | 2014-05-20 14:41:14 +0300 |
---|---|---|
committer | Cristian Bica <cristian.bica@gmail.com> | 2014-05-20 14:41:14 +0300 |
commit | 0227af92b1851d5eac4cb423dc0c9935dbc733a3 (patch) | |
tree | c84c1d07937ca4a1837df063f3f3d59025581c1e | |
parent | 2d19c711d041dd955d3fcaf952d101df9241a65e (diff) | |
download | rails-0227af92b1851d5eac4cb423dc0c9935dbc733a3.tar.gz rails-0227af92b1851d5eac4cb423dc0c9935dbc733a3.tar.bz2 rails-0227af92b1851d5eac4cb423dc0c9935dbc733a3.zip |
Added logging capabilities
-rw-r--r-- | lib/active_job/base.rb | 5 | ||||
-rw-r--r-- | lib/active_job/enqueuing.rb | 1 | ||||
-rw-r--r-- | lib/active_job/log_subscriber.rb | 19 | ||||
-rw-r--r-- | lib/active_job/logging.rb | 5 |
4 files changed, 29 insertions, 1 deletions
diff --git a/lib/active_job/base.rb b/lib/active_job/base.rb index 77b929d4af..ed402bd8d3 100644 --- a/lib/active_job/base.rb +++ b/lib/active_job/base.rb @@ -1,11 +1,14 @@ require 'active_job/queue_adapter' require 'active_job/queue_name' require 'active_job/enqueuing' +require 'active_job/logging' +require 'active_job/log_subscriber' 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..81859d8da1 --- /dev/null +++ b/lib/active_job/log_subscriber.rb @@ -0,0 +1,19 @@ +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..7bd77b7ca5 --- /dev/null +++ b/lib/active_job/logging.rb @@ -0,0 +1,5 @@ +module ActiveJob + module Logging + mattr_accessor(:logger) { ActiveSupport::Logger.new(STDOUT) } + end +end |