I have a carrier load that takes a long time to process, but needs to be completed before the user can continue the next action in the browser. I use the loading of the Ajax file in the interface, so the user interface of the application updates the information about loading and processing. This works fine in my dev environment because the timeout on my dev server is relatively long, but not very good on Heroku, since Cedar will expire the request after 30 seconds if no response is sent. I am trying to create a streaming response that sends a space every couple of seconds until the process completes, creating a response object that responds to each of them this way:
class LongPoller
def initialize(yield_every=2,task)
@yield_every = yield_every
@task = task
end
def each
t = Thread.new(&@task)
while t.alive?
sleep @yield_every
yield ' '
end
yield t.value.to_json
end
end
, , Thin, , .
- , ?