I am using spring batch deployed on PCF and created 2 rest call using rest controller.
1) Start - Rest call will invoke spring batch -working fine
2) End - Rest call will terminate spring batch - Not able to find solution or method how to do that
I am looking how to terminate spring batch job in between running program same like when we kill java process id and terminate .
*/
@RestController
public class BatchTriggerController {
private static final Logger log = LogManager.getLogger(BatchTriggerController.class);
@Autowired
JobLauncher jobLauncher;
@Autowired
Job job;
@RequestMapping(value = "/trigger/start", method = RequestMethod.GET)
public String invokeBatch() {
//
long start = System.currentTimeMillis();
JobParameters jobParameters = new JobParametersBuilder().addLong("time", System.currentTimeMillis()).toJobParameters();
long end = System.currentTimeMillis();
NumberFormat formatter = new DecimalFormat("#0.00000");
System.out.print("Execution time is " + formatter.format((end - start) / 1000d) + " seconds");
log.info("loader Execution time is " + formatter.format((end - start) / 1000d) + " seconds");
try {
jobLauncher.run(job, jobParameters);
} catch (Exception e) {
e.printStackTrace();
log.error("BatchTriggerController Exception "+e.getMessage());
return "Fail";
}
return "Success";
}
@RequestMapping(value = "/trigger/stop", method = RequestMethod.GET)
public String stopBatch() {
//
long start = System.currentTimeMillis();
JobParameters jobParameters = new JobParametersBuilder().addLong("time", System.currentTimeMillis()).toJobParameters();
long end = System.currentTimeMillis();
NumberFormat formatter = new DecimalFormat("#0.00000");
System.out.print("Execution time is " + formatter.format((end - start) / 1000d) + " seconds");
log.info("loader Execution time is " + formatter.format((end - start) / 1000d) + " seconds");
try {
jobLauncher.STOP(job, jobParameters);//NO METHOD STOP
} catch (Exception e) {
e.printStackTrace();
log.error("BatchTriggerController Exception "+e.getMessage());
return "Fail";
}
return "Success";
}