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 @@ cron create
job name
+
job group
+
cron expression
+
+ id="edit_cron"/>
job status
-
job description
+