如何在 Grails 中获取后台操作(Quartz 作业?)的状态
我试图完成触发石英作业,并以某种方式将该作业绑定到特定用户或会话,并能够检查作业的状态。
基本上,我需要在每次用户登录时触发一项作业。该作业会下载特定于该用户的信息——这可能需要几分钟的时间,并且对于同时登录的多个用户来说,其中许多作业可能会异步触发。
现在的问题是,当作业运行时,用户可能会访问网站上的不同页面——也就是说,我不想打断它们,所以我需要一种方法来触发作业,但首先检查是否有已经为该特定用户运行。我还需要能够在工作完成后更新 UI。
我在这里有点茫然……我在谷歌上找不到太多东西,所以我真的很感激任何见解。
I am trying to accomplish triggering a quartz job and somehow bind that job to a specific user or session and have the ability to check the status of the job.
Basically I need to trigger a job every time a user logs in. This job downloads information specific to that user -- it could take several minutes, and many of these jobs could be triggered async'ly for multiple users logging in at the same time.
Now the thing is, while the job is running, the user could be visiting different pages on the site -- that is, I don't want to interrupt them, so I need a way to trigger the job, but first check if there is already one running for that specific user. I also need the ability to update the UI once the job is finished.
I'm sort of at a loss here.. I can't find much on Google so I would really appreciate any insight.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看执行器插件。它将一个
callAsync()
MetaMethod 添加到您的 Grails 工件中,该方法将返回一个 JavaFuture
对象,以便您可以检索异步调用的状态和结果。如果您还需要 Quartz 的调度功能,只需将您的逻辑放入 Grails Service 中,然后根据情况从 Quartz 作业或通过
callAsync()
调用 Service 方法即可。Check out the Executor Plugin. It adds a
callAsync()
MetaMethod to your Grails artefacts, which will return a JavaFuture
object, so that you can retrieve the status and results of your async call.If you need Quartz's scheduling ability as well, just put your logic in a Grails Service and call the Service method from the Quartz job or via
callAsync()
depending on the circumstances.我只能提供一个建议。我不确定您为什么要问如何在每次用户登录时触发作业。为此,您需要做的就是将作业中的所有代码放入一个服务中,以便在登录控制器中您也可以在用户登录时调用该服务代码。
作业类中:
在控制器中:
在 跟踪作业是否正在运行,有多种方法可以做到这一点,例如保留特定于用户的标志,并在运行作业之前检查该标志。
I can only offer a suggestion. I'm not sure why you're asking how to trigger a job every time a user logs. For this, all you need to do is put all the code in the job into a service so that in the login controller you can also call the service code when the user logs in.
In the job class:
In the controller:
As far as keeping track if the job is running, there are several ways to do this such as keep a flag specific to the user, and checking the flag before running the job.