Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 2.3.X - Execute code after request was rendered and returned?

is it possible in rails 2.3.X to start a new chain of commands after a request has been rendered and returned to the requestor?

I need that feature in order to work with an asynchronous API on the other side: They expect a response to their request and after that response is done my rails app should send a new http-request to them (post something to their API)...

What are the possibilities here? Is there something like a after_render hook? Should I make use of threads or background tasks and how could this be done?

I would be very glad for some solutions :-)

Kind regards

UPDATE: The Return-Code (eg. 200) should be sent to the requestor before the other calls are executed

like image 576
Bijan Avatar asked Dec 01 '10 14:12

Bijan


1 Answers

The easiest thing to do is spawn a new thread. This is assuming that it is a lightweight call and you don't need advanced error logging or retry logic.

Thread.new do
  puts  "call the api"
end
like image 186
Aaron Scruggs Avatar answered Sep 29 '22 11:09

Aaron Scruggs