【发布时间】:2014-03-27 11:49:02
【问题描述】:
有没有办法让我之前在 Controller 中启动的正在运行的作业?这里我有启动器的控制器和任务执行器配置:
@Controller
@RequestMapping(value = "/action/file")
public class ArquivoController {
@Autowired
private JobLauncher jobLauncher;
@Autowired
@Qualifier(value = "jobValidateFile")
private Job jobValidateFile;
@RequestMapping(value = "/validate", method = RequestMethod.GET)
public @ResponseBody Map<String, Object> validate(@RequestParam Long fileId, Principal user) {
Map<String, JobParameter> parameters = new HashMap<String, JobParameter>();
parameters.put("fileId", new JobParameter(fileId));
JobExecution execution = this.jobLauncher.run(this.jobValidateFile, new JobParameters(parameters));
return new ResponseBuilder().toSuccessResponse();
}
@RequestMapping(value = "/status", method = RequestMethod.GET)
public @ResponseBody Map<String, Object> seeStatus(@RequestParam Long fileId) {
// Get the running job status here.
return new ResponseBuilder().toSuccessResponse();
}
}
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
<property name="taskExecutor">
<bean class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
</property>
</bean>
如您所见,我将启动器作为异步任务。我正在尝试做的是一点一点地获取批次状态。例如,我要制作一个每分钟调用“seeStatus”方法的javascript。
谢谢。
【问题讨论】:
标签: java spring spring-mvc batch-processing spring-batch