Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible in rails to return response and keep processing the data the client submitted?

I have a webservice that processes user submitted data. The user doesn't need to receive a response based on that data, he just needs to submit it. However, I do need to process that data. Currently the processing takes place directly as a response to the post action, and after the processing, it return a statuscode. This normally takes 0.5s - 2s, but sometimes much longer, when a user submits a lot of data.

Is it possible in Rails to spawn a new thread for processing that data, while returning the status code (and thus finishing the request for the user)?

like image 295
Peterdk Avatar asked Dec 14 '12 23:12

Peterdk


People also ask

What does Before_action do in Rails?

When writing controllers in Ruby on rails, using before_action (used to be called before_filter in earlier versions) is your bread-and-butter for structuring your business logic in a useful way. It's what you want to use to "prepare" the data necessary before the action executes.

What is request referer in rails?

request.referer gives you the previous URL or / if none. It is usually used to redirect the user back to the previous page (link)

What does post do in Rails?

By using the post method rather than the get method, Rails will define a route that will only respond to POST methods. The POST method is the typical method used by forms all over the web. You now need to create the create action within the PostsController for this to work.

What is the role of rails controller?

The Rails controller is the logical center of your application. It coordinates the interaction between the user, the views, and the model. The controller is also a home to a number of important ancillary services. It is responsible for routing external requests to internal actions.

How do you pass a value from view to controller in Ruby on Rails?

View is already displayed on the user browser, so Sending Data from View to Controller is only that the user inserts Data. To send Data from View to Controller, it's the same as sending Data in a web service, so we can use GET / POST Request to send it.


1 Answers

Resque, Delayed Job, or Sidekiq should suit your needs.

You can find links to these three, and a couple more here: https://www.ruby-toolbox.com/categories/Background_Jobs

like image 124
doesterr Avatar answered Oct 12 '22 11:10

doesterr