I’m building a Ruby web service which accepts POST or PUT requests that tell it to do some work. The work involves moving some big files around – sometimes over a network – so these requests could take a while. I’m building a separate service – in Python, or Node, or whatever – that handles scheduling & monitoring requests to the Ruby service.
I’d like to send some kind of periodical progress report on the behaviour of the Ruby app back to the scheduler. Perhaps a line every time a discrete operation is completed successfully, such as the moving of one file.
Is this possible with a standard Rack app? FYI I’m using the Camping framework It’s not dissimilar from Sinatra, etc. Usually you send the response by just returning from the method:
def get
@status = 404
@headers['Content-Type'] = 'application/json'
return Yajl::Encoder.new.encode({error: 'forbidden', reason: 'I don't like you'})
end
I know that my process is managed by the Rack / web server interface, so I don’t know whether it’s possible in Rack to send a streaming response without digging into the way the framework works and talks to Rack. Can someone give me some pointers here?
And yes, I know that Ruby isn’t a preferred solution for streaming HTTP servers 😉
Sounds like you need a chunked transfer. There is a
Rack::Chunkedmiddleware for it too within Rack.