-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectBatchService.java
More file actions
37 lines (31 loc) · 1.19 KB
/
ProjectBatchService.java
File metadata and controls
37 lines (31 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package NextLevel.demo.project.batch;
import NextLevel.demo.exception.CustomException;
import NextLevel.demo.exception.ErrorCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@Service
@Slf4j
@RequiredArgsConstructor
public class ProjectBatchService {
private final JobLauncher jobLauncher;
private final Job projectStatusJob;
@Scheduled(cron = "${scheduler.day}")
public void runProjectStatusJob() {
try{
JobParameters jobParameters = new JobParametersBuilder()
.addLong("time", 1L)
.toJobParameters();
jobLauncher.run(projectStatusJob, jobParameters);
log.info("Project status job finished");
} catch (Exception e){
e.printStackTrace();
throw new CustomException(ErrorCode.SIBAL_WHAT_IS_IT, e.getMessage());
}
}
}