views:

70

answers:

2

What is an elegant way to perform polling while the user is waiting? This is what i mean:

1) User clicks a bottom
2) Server performs an action that might take a few minutes
3) Want the page to constantly poll the server for updates
4) if not ready, returns back a status message with updates, if ready, show time taken

Did you have any experience with this before, and if so, how did you handle this with the most elegant way possible?

Links to any useful Gems, jQuery plugins very much appreciated!

A: 

In this case, if I have control over the server, I would send a status update message regularly (every 2-5 seconds, depends) from the server to the client. This way, no polling is taking place, neither on the server, nor on the client.

If you do not have this kind of control over the server, then I guess the only thing left is polling. Maybe a synchronous read with a timeout .. ?

Michael
A: 

I think this solution might be practical for you. It involves a background job on a new thread and uses a progress instance variable which you can query via ajax.

Kitto