jQuery - 轮询作业队列
我有一个包含作业队列的数据库表。一个单独的程序处理这些作业。我想提供一个网页供用户观看队列的进度。用于查询表并以 JSON 格式返回的服务器端脚本没有问题。
我读过一些关于 jQuery 和 PeriodicalUpdater 插件 的文章。我想知道是否有可能使用这个插件来创建一个可视队列(基本解释是一个单列表,队列中每个条目一行),其中已完成的作业将在下一个队列中删除投票时间。正如我所说,服务器端脚本不是问题,我只是无法理解这种 UI/动画。任何进一步阅读的提示将不胜感激,或者如果我完全找错了树,也请告诉我。
提前致谢
I have a database table which contains a queue of jobs. A separate program processes these jobs. I want to provide a webpage for users to watch the progress of the queue. The Server side scripting to query the table and return it in a JSON format is no problem.
I've done some reading on jQuery and the PeriodicalUpdater plugin. I'm wondering if it is at all possible to use this plugin to create a visual queue (a basic explanation would be a one column table, with a row per entry in the queue), where jobs which have been completed are removed the next time it polls. As I say, the server side script isn't a problem, I just can't get my head around this sort of UI/Animation. Any tips for further reading would be appreciated, or if I'm barkin up the wrong tree entirely please let me know also.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不熟悉 periodicalupdater 插件,但如果我是你,我会考虑简单地使用 JavaScript 的“setTimeout”函数。 setTimeout 允许您以指定的时间间隔运行函数。
有关与您的情况相关的示例,请参见此处:
注意:一秒有 1000 毫秒,因此该函数设计为每 5 秒触发一次。
另外...
我假设队列表中的每个条目都有一个与其关联的唯一 ID。在您的 HTML 主页面中,我将打印出如下所示的表格:
换句话说,为队列表中的每一行分配与表中条目相同的 ID。然后,当您的 AJAX 调用返回结果时,您可以检查是否有任何队列项目已完成。如果有,您可以执行以下操作:
I'm not familiar with the PeriodicalUpdater plugin, but if I was you, I would look into simply using JavaScript's "setTimeout" function. setTimeout allows you to run a function at a specified interval.
For an example that's relevant to your situation, see here:
Note: There are 1000 milliseconds in one second, so that function is designed to fire off every 5 seconds.
In addition...
I'm assuming that each entry in your queue table has a unique ID associated with it. Within your main HTML page, I would print out the table like this:
In other words, assign each row in your queue table the same ID that the entry in your table has. Then, when your AJAX call returns a result, you can check to see if any of the queue items have been finished. If they have, you can do something like:
您不需要长时间轮询。您只需要定期使用 ajax 调用来使用 setInterval 刷新队列。每次调用服务器时,您都会获取整个现有队列,与当前队列进行比较,并删除不再存在的队列:
You don't need long polling. You just need a periodic ajax call to refresh the queue using setInterval. Every time you call the server, you get the entire existing queue, compare to the current queue, and remove the ones no longer present: