Rails:无论过滤器链中止如何,都让逻辑在请求结束时运行?
Rails 文档中是否讨论了一种可靠的机制,用于在请求结束时调用函数,而不管过滤器链是否中止?
它不是后过滤器,因为如果任何先前的过滤器重定向或呈现,后过滤器不会被调用。
对于上下文,我尝试在每个请求末尾将一些结构化分析/报告信息放入应用程序日志中。此信息是在整个请求生命周期中通过封装在自定义控制器访问器中的实例变量收集的,并在最后转储到 JSON blob 中以供后处理脚本使用。
我的最终目标是生成有关应用程序逻辑查询分布(依赖于控制器逻辑的内容,而不仅仅是请求 URI 和参数)、性能概况(在特定数据库查询上花费的时间或在 Web 服务上阻塞的时间)、故障率(包括无效传入)的报告。被 before_filter 验证规则拒绝的请求),以及大量无法从应用程序和 apache 日志中的基本信息中真正解析的其他内容。
在更高的层面上,是否有不同的“轨道方式”可以解决我的应用程序分析目标?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要一个可以在应用程序完成请求后执行代码的中间件。请参阅指南中的更多信息:http://guides.rails.info/rails_on_rack.html
更新链接:https://guides.rubyonrails.org/rails_on_rack.html
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
今天围绕过滤器应该可以解决这个问题: http://apidock.com/rails/ActionController/Filters/ClassMethods
(非常旧的线程 - 但在我找到答案之前遇到了这个)
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)