Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat's the fastest way for a true sinatra(ruby/rack) after_filter?
    primarykey
    data
    text
    <p>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. </p> <p>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. </p> <p>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?</p> <p>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. </p> <p>I've seen this question: <a href="https://stackoverflow.com/questions/367151/multipart-response-in-ruby-rack">Multipart-response-in-ruby</a> 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.</p> <p>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 <a href="http://github.com/rack/rack-contrib/blob/ec0fb58ee4782b29483cba58833d1a67ac33252e/lib/rack/contrib/callbacks.rb" rel="nofollow noreferrer">Rack::Callbacks </a> implementation(added comment):</p> <pre><code>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 </code></pre> <p>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 <a href="http://www.espace.com.eg/neverblock" rel="nofollow noreferrer">NeverBlock</a> 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)?</p> <p>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.</p> <p>Thanks for reading or answering my question! :-)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload