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.
Share
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:
But this is only suitable for very small apps. Do not try this under heavy load.