长服务器端操作处理使用AJAX?服务器端、操作、AJAX

2023-09-10 17:33:26 作者:神袭。

我有一个的尤其的运行时间长了是会得到运行时 用户presses界面上的按钮,我想知道什么是最好的 的方式来表示这个回客户端。

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.

的操作是填充事实表了数年价值的数据 这将需要大约20分钟,我不打算接口是 同步。即使它是生成大量数据服务器侧的, 我还是喜欢一切仍然因为当月的数据响应的 用户当前正在观看将被相当快地更新这是没有问题的。

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?

你是怎么做到的?

推荐答案

的code服务器端的部分应该产卵或使用过程中,生活在Web服务器外部进行通信。使用网页code来运行,应该由一个后台程序来处理的任务只是马虎的工作。

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.