什么是真正的sinatra(ruby / rack)after_filter的最快的方式? [英] What's the fastest way for a true sinatra(ruby/rack) after_filter?

查看:132
本文介绍了什么是真正的sinatra(ruby / rack)after_filter的最快的方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,这是一个简单的任务。在我向客户端呈现html之后,我想使用请求中的信息执行db调用。

Okay it's a simple task. After I render html to the client I want to execute a db call with information from the request.

我使用sinatra,因为它是一个轻量级的微框架,但真的我喜欢ruby的任何东西,如果它更快/更容易(Rack?我只想得到的url和重定向客户端其他地方基于url。

I am using sinatra because it's a lightweight microframework, but really i up for anything in ruby, if it's faster/easier(Rack?). I just want to get the url and redirect the client somewhere else based on the url.

那么如何使用rack / sinatra做一个真正的after_filter。和after_filter我的意思是响应发送到客户端。

So how does one go about with rack/sinatra a real after_filter. And by after_filter I mean after response is sent to the client. Or is that just not dooable without threads?

我分叉sinatra并在过滤后添加,但没有办法刷新响应,甚至send_data,这是假设为流文件(这显然是二进制)等待after_filters。

I forked sinatra and added after filters, but there is no way to flush the response, even send_data which is suppose to stream files(which is obviously for binary) waits for the after_filters.

我看到这个问题: Multipart-response-in-ruby 但是答案是rails。

I've seen this question: Multipart-response-in-ruby but the answer is for rails. And i am not sure if it really flushes the response to the client and then allows for processing afterwards.

Rack :: Callbacks在回调之前和之后都有一些回调,但即使是那些回调函数就像在响应发送到客户端之前运行的 Rack :: Callbacks 实现(添加注释):

Rack::Callbacks has some before and after callbacks but even those look like they would run before the response is ever sent to the client here's Rack::Callbacks implementation(added comment):

def call(env)
  @before.each {|c| c.call(env) }
  response = @app.call(env)
  @after.each {|c| c.call(env) }
  response 
  #i am guessing when this method returns then the response is sent to the client.
end

所以我知道我可以通过shell使用rake调用一个后台任务。但这将是很好,不要有太多...还有 NeverBlock ,但那是好的用于执行单独的进程,而不会延迟响应,还是仍然使应用程序等待整体(我认为)?

So i know I could call a background task through the shell with rake. But it would be nice not to have too... Also there is NeverBlock but is that good for executing a separate process without delaying the response or would it still make the app wait as whole(i think it would)?

我知道这是很多,但在short是简单的after_filter,真正运行后响应发送在ruby / sinatra / rack。

I know this is a lot, but in short it's simple after_filter that really runs after the response is sent in ruby/sinatra/rack.

感谢阅读或回答我的问题! : - )

Thanks for reading or answering my question! :-)

推荐答案

将run_later端口修改为rails以执行文件可用的技巧:

Modified run_later port to rails to do the trick the file is available here:

http://github.com/pmamediagroup/sinatra_run_later/tree/主人

这篇关于什么是真正的sinatra(ruby / rack)after_filter的最快的方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆