Search code examples
phpjqueryajaxusability

Dealing with long server-side operations using ajax?


I've a particularly long operation that is going to get run when a user presses a button on an interface and I'm wondering what would be the best way to indicate this back to the client.

The operation is populating a fact table for a number of years worth of data which will take roughly 20 minutes so I'm not intending the interface to be synchronous. Even though it is generating large quantities of data server side, I'd still like everything to remain responsive since the data for the month the user is currently viewing will be updated fairly quickly which isn't a problem.

I thought about setting a session variable after the operation has completed and polling for that session variable. Is this a feasible way to do such a thing? However, I'm particularly concerned about the user navigating away/closing their browser and then all status about the long running job is lost.

Would it be better to perhaps insert a record somewhere lodging the processing record when it has started and finished. Then create some other sort of interface so the user (or users) can monitor the jobs that are currently executing/finished/failed?

Has anyone any resources I could look at?

How'd you do it?


Solution

  • The server side portion of code should spawn or communicate with a process that lives outside the web server. Using web page code to run tasks that should be handled by a daemon is just sloppy work.