Reputation: 537
When a user posts a comment to my Rails application, I want the comment to be pushed to an external web service. This external web service could be slow, so I want to make this push asynchronously. I am not interested in the response from the web service.
Upvotes: 0
Views: 94
Reputation: 230481
The best way to use a task queue and background worker.
Take a look at Sidekiq, for example. Or BackgroundJob. Or Resque.
Basically, in your rails app you say "I want this be called in background" and put a task to a queue (backed by redis/mysql/erlang/whatever). Then another process (background worker) retrieves tasks from the queue and executes them.
For a quick-and-dirty solution you can use threads:
Thread.new do
# this stuff will be executed asynchronously
end
But this is only suitable for very small apps. Do not try this under heavy load.
Upvotes: 1