|
6 | 6 | import org.quartz.JobKey; |
7 | 7 | import org.quartz.Scheduler; |
8 | 8 | import org.quartz.SchedulerException; |
| 9 | +import org.springframework.batch.core.JobParameters; |
| 10 | +import org.springframework.batch.core.JobParametersBuilder; |
| 11 | +import org.springframework.batch.core.JobParametersInvalidException; |
| 12 | +import org.springframework.batch.core.configuration.JobRegistry; |
| 13 | +import org.springframework.batch.core.launch.JobLauncher; |
| 14 | +import org.springframework.batch.core.launch.NoSuchJobException; |
| 15 | +import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException; |
| 16 | +import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException; |
| 17 | +import org.springframework.batch.core.repository.JobRestartException; |
9 | 18 | import org.springframework.beans.factory.annotation.Autowired; |
10 | 19 | import org.springframework.data.domain.Page; |
11 | 20 | import org.springframework.data.domain.Pageable; |
@@ -33,6 +42,12 @@ public class JobServiceImpl implements JobService { |
33 | 42 | @Autowired |
34 | 43 | private Scheduler scheduler ; |
35 | 44 |
|
| 45 | + @Autowired |
| 46 | + JobLauncher jobLauncher; |
| 47 | + |
| 48 | + @Autowired |
| 49 | + JobRegistry jobRegistry; |
| 50 | + |
36 | 51 | @Override |
37 | 52 | public Page<JobEntity> loadJobPageable(Pageable pageable, String name, Integer type, Integer status, String triggerName, String springJobName) { |
38 | 53 | Specification<JobEntity> queryCondition = new Specification<JobEntity>() { |
@@ -65,6 +80,12 @@ public Predicate toPredicate(Root<JobEntity> root, CriteriaQuery<?> criteriaQuer |
65 | 80 | return jobDao.findAll(queryCondition, pageable); |
66 | 81 | } |
67 | 82 |
|
| 83 | + @Override |
| 84 | + public void launch(Long jobId) throws NoSuchJobException, JobParametersInvalidException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException { |
| 85 | + JobEntity jobEntity = jobDao.getOne(jobId); |
| 86 | + jobLauncher.run(jobRegistry.getJob(jobEntity.getSpringJobName()),new JobParametersBuilder().addDate("#CURRENNCY",new Date()).toJobParameters()); |
| 87 | + } |
| 88 | + |
68 | 89 | @Override |
69 | 90 | public JobEntity save(JobEntity jobEntity) { |
70 | 91 | jobEntity.setUpdatedAt(new Date()); |
|
0 commit comments