0

I'm watching series of railscasts dedicated to background jobs (delayed_job/resque/sidekiq etc). In several episodes Ryan uses request to external webservice as example of long running task. Web services are unpredictable and sometimes could answer with big delay or even be unavailable, but 90% is that modern web service would answer quickly, and time, consumed on job enqueuing would be longer than having no job (I think). So my question is there any light alternatives to jobs in processing probably long requests and not blocking UI? Obligatory condition is that request logic is incapsulated in ruby class and could not be implemented in simple ajax request.

2
  • When you're thinking for too long about performance you might want to start measuring it. Something being "heavy" or "light" is too context-dependent to make any assumptions. Lighter alternatives... I can think of a Websocket connection that's driven by a thread on the server. But I don't think Rails can handle that well.
    – D-side
    Dec 13, 2015 at 19:22
  • Websockets are kind of exotic for classic rails app, but I'm on contrary asking for often used solution for sending request to service and showing some modal window with looping progress and words something like "wait a little, while your request being processed". And refreshing the page when response come Dec 13, 2015 at 19:45

1 Answer 1

0

You can use HTTParty (httparty gem) for inline requests. See https://github.com/jnunemaker/httparty

2
  • The question was not about what library to use for service communication (httparty/faraday/etc), but about how to correctly wrap this communication logic in app. One way is to execute as background jobs, which creates overhead. Are there lighter alternatives? Dec 13, 2015 at 18:40
  • Alternative is to use inline access and analyze the response. response = HTTParty.send method, url; if response.response.is_a?(Net::HTTPSuccess)
    – Alexei.B
    Dec 14, 2015 at 1:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.