开发者

Rails: getting logic to run at end of request, regardless of filter chain aborts?

Is there a reliable mechanism discussed in rails documentation for calling a function at the end of the request, regardless of filter chain aborts?

It's not after filters, because after filters don't get开发者_如何学编程 called if any prior filter redirected or rendered.

For context, I'm trying to put some structured profiling/reporting information into the app log at the end of every request. This information is collected throughought the request lifetime via instance variables wrapped in custom controller accessors, and dumped at the end in a JSON blob for use by a post-processing script.

My end goal is to generate reports about my application's logical query distribution (things that depend on controller logic, not just request URIs and parameters), performance profile (time spent in specific DB queries or blocked on webservices), failure rates (including invalid incoming requests that get rejected by before_filter validation rules), and a slew of other things that cannot really be parsed from the basic information in the application and apache logs.

At a higher level, is there a different "rails way" that solves my app profiling goal?


You need a middleware that can execute code after the application has finished the request. See for more information in the guide: http://guides.rails.info/rails_on_rack.html

Updated link: https://guides.rubyonrails.org/rails_on_rack.html


around filters should solve this problem today: http://apidock.com/rails/ActionController/Filters/ClassMethods

(really old thread - but came across this before I found the answer)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜