在dropwizard中,我需要实现异步作业并轮询其状态。我在资源中有2个端点:
@Path("/jobs")
@Component
public class MyController {
@POST
@Produces(MediaType.APPLICATION_JSON)
public String startJob(@Valid MyRequest request) {
return 1111;
}
@GET
@Path("/{jobId}")
@Produces(MediaType.APPLICATION_JSON)
public JobStatus getJobStatus(@PathParam("id") String jobId) {
return JobStatus.READY;
}
}
Run Code Online (Sandbox Code Playgroud)
我正在考虑使用石英来开始工作,但只能一次,并且无需重复。当请求状态时,我将获得触发器状态。但是,将石英用于非预定用途的想法看起来很奇怪。有没有更好的方法呢?也许dropwizard本身提供了更好的工具?将提出任何建议。
更新:我也在看https://github.com/gresrun/jesque,但是找不到任何方法来轮询正在运行的作业的状态。