玩! - 动态结束作业
因此,假设我从控制器异步启动一项作业,然后渲染一些模板。
MyJob job = new MyJob();
job.doJob();
render();
MyJob 看起来像:
import play.jobs.*;
public class MyJob extends Job {
public void doJob() {
// execute some application logic here until I say to quit via a controller method
}
}
从 UI 中,我执行一些操作,然后触发对控制器中另一个路由的请求,这将结束作业。我不想在客户端处理复杂、连续的 DAO 操作,那么解决这个问题的最佳方法是什么?我有一个 EC2 弹性缓存设置,因此主要问题是为作业分配 ID。
job.endJob(id); ?
So, let's say I start a job from a controller asynchronously and then render some template.
MyJob job = new MyJob();
job.doJob();
render();
MyJob looks like:
import play.jobs.*;
public class MyJob extends Job {
public void doJob() {
// execute some application logic here until I say to quit via a controller method
}
}
From the UI, I do some actions, and I trigger a request to another route in the controller which would end the job. I don't want to have complicated, continuous DAO actions handled on the client side, so what is the best way to go about this? I have an EC2 elastic cache setup, so the main problem is assigning an ID to a job.
job.endJob(id); ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您查看 JobsPlugin 类 -它使用ScheduledThreadPoolExecutor执行器来维护作业列表。
这个类有一个 remove方法,你可以尝试使用。
If you look at JobsPlugin class - it uses
ScheduledThreadPoolExecutor executor
to maintain a list of jobs.This class has a remove method, which you can try to use.
我不知道有什么方法可以轻松停止作业。由于 Play 是无状态的,因此最好的选择可能是在数据库中添加一些标志,作业可以检查该标志以决定停止,但对我来说这看起来不是一个很好的解决方案。
您是否在 Play 中检查过Continuations?我相信它们可能更适合您的场景。
I'm not aware of a way to easily stop a Job. As Play is stateless, probably your best bet would be to have some flag in the database that the job can check to decide to stop, but doesn't look a great solution to me.
Have you checked Continuations in Play? I believe they may suit your scenario better.