开发者

How do I process ActiveSupport::Notifications events?

开发者 https://www.devze.com 2023-01-29 06:22 出处:网络
I\'ve looked at the documentation for ActiveSupport::Notifications but I\'m a little unclear about how to use it. Here\'s what I have right now:

I've looked at the documentation for ActiveSupport::Notifications but I'm a little unclear about how to use it. Here's what I have right now:

class Foo
  ...

  def xyz
    # other stuff
    ActiveSupport::Notifications.instrument(:interesting)
      expensive_operation(123, 'apple')    # We want to instrument this.
    end
  end
end

What I would like to do is have another class, Auditor, invoke puts "event #{e开发者_JAVA技巧vent}" whenever the interesting event is raised. How do I do that?


A good resources is from railscast.com

http://railscasts.com/episodes/249-notifications-in-rails-3

Another resource that you can take a look at is Jose Valim's book Crafting Rails Application.


Here are a few good resources to get you started:

  • Using ActiveSupport::Notifications and ActiveSupport::Concern To Create An Audit Trail
  • Digging Deep with ActiveSupport::Notifications
  • ActiveSupport::Notifications API Documentation
  • Active Support Instrumentation Rails Guide - This contains a list of all available notifications that you can subscribe to.
  • RailsCasts #249 - Notifications in Rails 3
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号