unnitallman
unnitallman

Reputation: 537

What is the best way to make an asynchronous push to an external web service from a Rails application?

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

Answers (1)

Sergio Tulentsev
Sergio Tulentsev

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 ///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

Related Questions