diff --git a/scheduler/boot-scheduler-quartz/README.md b/scheduler/boot-scheduler-quartz/README.md index ab5d5f363..92e064e07 100644 --- a/scheduler/boot-scheduler-quartz/README.md +++ b/scheduler/boot-scheduler-quartz/README.md @@ -32,4 +32,4 @@ You can also run the application using Maven as follows: * Swagger UI: http://localhost:8080/swagger-ui.html * Actuator Endpoint: http://localhost:8080/actuator * PGAdmin : http://localhost:5050 - +* UI : http://localhost:8080/index diff --git a/scheduler/boot-scheduler-quartz/pom.xml b/scheduler/boot-scheduler-quartz/pom.xml index 9f7ca401b..c154a3a6f 100644 --- a/scheduler/boot-scheduler-quartz/pom.xml +++ b/scheduler/boot-scheduler-quartz/pom.xml @@ -55,6 +55,10 @@ org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-validation + diff --git a/scheduler/boot-scheduler-quartz/src/main/java/com/scheduler/quartz/config/WebMvcConfig.java b/scheduler/boot-scheduler-quartz/src/main/java/com/scheduler/quartz/config/WebMvcConfig.java index 9e49d0845..415963323 100644 --- a/scheduler/boot-scheduler-quartz/src/main/java/com/scheduler/quartz/config/WebMvcConfig.java +++ b/scheduler/boot-scheduler-quartz/src/main/java/com/scheduler/quartz/config/WebMvcConfig.java @@ -2,6 +2,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Configuration; +import org.springframework.lang.NonNull; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -11,7 +12,7 @@ public class WebMvcConfig implements WebMvcConfigurer { private final ApplicationProperties properties; @Override - public void addCorsMappings(CorsRegistry registry) { + public void addCorsMappings(@NonNull CorsRegistry registry) { registry.addMapping(properties.getCors().getPathPattern()) .allowedMethods(properties.getCors().getAllowedMethods()) .allowedHeaders(properties.getCors().getAllowedHeaders()) diff --git a/scheduler/boot-scheduler-quartz/src/main/java/com/scheduler/quartz/job/SchedulerRegistrationService.java b/scheduler/boot-scheduler-quartz/src/main/java/com/scheduler/quartz/job/SchedulerRegistrationService.java index bf4622112..31824f96e 100644 --- a/scheduler/boot-scheduler-quartz/src/main/java/com/scheduler/quartz/job/SchedulerRegistrationService.java +++ b/scheduler/boot-scheduler-quartz/src/main/java/com/scheduler/quartz/job/SchedulerRegistrationService.java @@ -36,7 +36,7 @@ Trigger triggerOddJob(JobDetail registerOddJob) { .forJob(registerOddJob.getKey()) .startAt(futureDate(10, DateBuilder.IntervalUnit.SECOND)) .withSchedule(simpleSchedule() - .withIntervalInSeconds(60) // Run every 2 seconds + .withIntervalInSeconds(120) // Run every 120 seconds .repeatForever() .withMisfireHandlingInstructionFireNow()) .build(); diff --git a/scheduler/boot-scheduler-quartz/src/main/java/com/scheduler/quartz/service/JobsService.java b/scheduler/boot-scheduler-quartz/src/main/java/com/scheduler/quartz/service/JobsService.java index 6c5783152..a8a82d830 100644 --- a/scheduler/boot-scheduler-quartz/src/main/java/com/scheduler/quartz/service/JobsService.java +++ b/scheduler/boot-scheduler-quartz/src/main/java/com/scheduler/quartz/service/JobsService.java @@ -36,11 +36,6 @@ public JobsService(Scheduler scheduler) { this.scheduler = scheduler; } - public void deleteJob(ScheduleJob scheduleJob) throws SchedulerException { - JobKey jobKey = JobKey.jobKey(scheduleJob.jobName(), scheduleJob.jobGroup()); - scheduler.deleteJob(jobKey); - } - public List getJobs() { List jobList = new ArrayList<>(); try { @@ -113,8 +108,11 @@ private void updateJobCronExpression(ScheduleJob scheduleJob) throws SchedulerEx } private void addJob(ScheduleJob scheduleJob) throws SchedulerException { + // Create TriggerKey for the job TriggerKey triggerKey = TriggerKey.triggerKey(scheduleJob.jobName(), GROUP_NAME); CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); + + // Throw exception if the job already exists if (trigger != null) { throw new SchedulerException("job already exists!"); } @@ -123,13 +121,16 @@ private void addJob(ScheduleJob scheduleJob) throws SchedulerException { ScheduleJob withJobId = scheduleJob.withJobId(String.valueOf(SampleJob.JOB_LIST.size() + 1)); SampleJob.JOB_LIST.add(withJobId); + // Build the JobDetail with recovery and durability JobDetail jobDetail = JobBuilder.newJob(SampleJob.class) .withIdentity(withJobId.jobName(), GROUP_NAME) + .withDescription(scheduleJob.desc()) .storeDurably() .requestRecovery() .build(); jobDetail.getJobDataMap().put("scheduleJob", withJobId.jobId()); + // Build the Trigger with Cron expression and associate it with the job CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(withJobId.cronExpression()); trigger = TriggerBuilder.newTrigger() .withIdentity(withJobId.jobName() + "-trigger", GROUP_NAME) @@ -143,4 +144,19 @@ public void pauseJob(ScheduleJob scheduleJob) throws SchedulerException { JobKey jobKey = JobKey.jobKey(scheduleJob.jobName(), scheduleJob.jobGroup()); scheduler.pauseJob(jobKey); } + + public void resumeJob(ScheduleJob scheduleJob) throws SchedulerException { + JobKey jobKey = JobKey.jobKey(scheduleJob.jobName(), scheduleJob.jobGroup()); + scheduler.resumeJob(jobKey); + } + + public void runJob(ScheduleJob job) throws SchedulerException { + JobKey jobKey = JobKey.jobKey(job.jobName(), job.jobGroup()); + scheduler.triggerJob(jobKey); + } + + public void deleteJob(ScheduleJob scheduleJob) throws SchedulerException { + JobKey jobKey = JobKey.jobKey(scheduleJob.jobName(), scheduleJob.jobGroup()); + scheduler.deleteJob(jobKey); + } } diff --git a/scheduler/boot-scheduler-quartz/src/main/java/com/scheduler/quartz/web/controller/JobsController.java b/scheduler/boot-scheduler-quartz/src/main/java/com/scheduler/quartz/web/controller/JobsController.java index 735a33dbc..d70ae790c 100644 --- a/scheduler/boot-scheduler-quartz/src/main/java/com/scheduler/quartz/web/controller/JobsController.java +++ b/scheduler/boot-scheduler-quartz/src/main/java/com/scheduler/quartz/web/controller/JobsController.java @@ -62,6 +62,34 @@ public Message pauseJob(ScheduleJob job) { return message; } + @PostMapping(value = "/resumeJob") + public Message resumeJob(ScheduleJob job) { + log.info("resumeJob params = {}", job); + Message message = Message.failure(); + try { + jobsService.resumeJob(job); + message = Message.success(); + } catch (Exception e) { + message.setMsg(e.getMessage()); + log.error("resumeJob ex:", e); + } + return message; + } + + @PostMapping(value = "/runJob") + public Message runJob(ScheduleJob job) { + log.info("runJob params = {}", job); + Message message = Message.failure(); + try { + jobsService.runJob(job); + message = Message.success(); + } catch (Exception e) { + message.setMsg(e.getMessage()); + log.error("runJob ex:", e); + } + return message; + } + @DeleteMapping(value = "/deleteJob") public Message deleteJob(ScheduleJob job) { log.info("deleteJob params : {}", job); diff --git a/scheduler/boot-scheduler-quartz/src/main/resources/application.properties b/scheduler/boot-scheduler-quartz/src/main/resources/application.properties index de09bdfa6..2aca129e6 100644 --- a/scheduler/boot-scheduler-quartz/src/main/resources/application.properties +++ b/scheduler/boot-scheduler-quartz/src/main/resources/application.properties @@ -14,6 +14,8 @@ spring.jpa.show-sql=false spring.jpa.open-in-view=false spring.data.jpa.repositories.bootstrap-mode=deferred spring.datasource.hikari.auto-commit=false +spring.datasource.hikari.pool-name=HikariPool-${spring.application.name} +spring.datasource.hikari.data-source-properties.ApplicationName=${spring.application.name} spring.jpa.hibernate.ddl-auto=none #spring.jpa.properties.hibernate.format_sql=true spring.jpa.properties.hibernate.jdbc.time_zone=UTC diff --git a/scheduler/boot-scheduler-quartz/src/main/resources/db/changelog/migration/01-init.xml b/scheduler/boot-scheduler-quartz/src/main/resources/db/changelog/migration/01-init.xml index 9d3b8b9b3..5b45d59dd 100644 --- a/scheduler/boot-scheduler-quartz/src/main/resources/db/changelog/migration/01-init.xml +++ b/scheduler/boot-scheduler-quartz/src/main/resources/db/changelog/migration/01-init.xml @@ -4,6 +4,6 @@ xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog - http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.2.xsd"> + https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.20.xsd"> diff --git a/scheduler/boot-scheduler-quartz/src/main/resources/logback-spring.xml b/scheduler/boot-scheduler-quartz/src/main/resources/logback-spring.xml index c53f88b80..66308a3db 100644 --- a/scheduler/boot-scheduler-quartz/src/main/resources/logback-spring.xml +++ b/scheduler/boot-scheduler-quartz/src/main/resources/logback-spring.xml @@ -20,5 +20,6 @@ + diff --git a/scheduler/boot-scheduler-quartz/src/main/resources/templates/index.html b/scheduler/boot-scheduler-quartz/src/main/resources/templates/index.html index 26ce47311..dd5b9d5c4 100644 --- a/scheduler/boot-scheduler-quartz/src/main/resources/templates/index.html +++ b/scheduler/boot-scheduler-quartz/src/main/resources/templates/index.html @@ -10,7 +10,9 @@ .input-group {margin-bottom: 5px;} .title {text-align:center; font-size:30px; margin-top:15px;} .btnCreate {text-align:right; margin:5px 15px;} - .head {border:solid; border-color:#8080805c; border-width:1px;} + .head { + border: 1px solid #8080805c; + } .line { border: 0; height: 1px; @@ -78,21 +80,25 @@
job name +
job group +
cron expression + + id="edit_cron"/>
job status - @@ -100,6 +106,7 @@
job description +