user1339462
user1339462

Reputation: 21

Is there a gem that provides "after_response" filter in Rails?

I am trying to do some intense optimization. I know of Delayed Jobs. But I do not want to even spend the time to create the Delayed Job before I send the response. I want to respond to the user and then worry about creating the Delayed Job after the response has been sent.

Is there some gem that does something like that?

Upvotes: 2

Views: 152

Answers (2)

Jesse Wolgamott
Jesse Wolgamott

Reputation: 40277

If it is lightweight, you can create a thread:

def show
  @record = Record.find(params[:id])
  Thread.new do
    Rails.logger.info "#{Time.now}"
    sleep 10
    Rails.logger.info "#{Time.now}"
  end
end

My log output with the above (and the respond renders instantly)

Started GET "/" for 127.0.0.1 at 2012-04-17 14:15:29 -0500
Processing by HomeController#public as HTML
2012-04-17 14:15:29 -0500
  Rendered home/public.html.haml within layouts/application (0.4ms)
  Rendered layouts/_navbar.html.haml (8.9ms)
  Rendered layouts/_flash.html.haml (0.1ms)
  Rendered layouts/_footer.html.haml (0.1ms)
Completed 200 OK in 210ms (Views: 202.3ms | ActiveRecord: 0.0ms)
2012-04-17 14:15:39 -0500

Upvotes: 2

Dominic Goulet
Dominic Goulet

Reputation: 8113

Delayed job. At some point, you have to store some information about the process you want to do after the response has been sent, and it's exactly what delayed job is for : store information about a process to run in the background.

Any other gem would do basically the same thing, which is store a bit of information about what to do. What's the problem with delayed job? if you have any specific issue with delayed job, you better get it solved than use any other unproved methods.

Upvotes: 0

Related Questions