Skip to content

Commit

Permalink
adds missing endpoints and polish
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Dec 22, 2024
1 parent bdae74b commit 79d0288
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 13 deletions.
2 changes: 1 addition & 1 deletion scheduler/boot-scheduler-quartz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions scheduler/boot-scheduler-quartz/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

<!-- webJars start -->
<!-- <dependency>-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScheduleJob> getJobs() {
List<ScheduleJob> jobList = new ArrayList<>();
try {
Expand Down Expand Up @@ -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!");
}
Expand All @@ -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)
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@

<logger name="com.scheduler.quartz" level="DEBUG"/>
<logger name="org.springframework" level="INFO"/>
<logger name="org.quartz" level="INFO" />

</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -78,28 +80,33 @@ <h4 class="modal-title" id="myModalLabel">cron create</h4>
<input type="hidden" class="form-control" id="jobId" name="jobId"/>
<div class="input-group">
<span class="input-group-addon">job name</span>
<label for="edit_name"></label>
<input type="text" alias="no-edit" name="jobName" class="form-control" id="edit_name"/>
</div>
<div class="input-group">
<span class="input-group-addon">job group</span>
<label for="edit_group"></label>
<input type="text" alias="no-edit" name="jobGroup" class="form-control" id="edit_group"/>
</div>
<div class="input-group">
<span class="input-group-addon">cron expression</span>
<label for="edit_cron"></label>
<input type="text" alias="no-edit" name="cronExpression" class="form-control"
id="edit_cron"/>
id="edit_cron"/>
</div>
<div class="input-group">
<span class="input-group-addon">job status</span>
<select id="edit_status" disabled="disabled" name="jobStatus" class="form-control"
data-size="10">
<label for="edit_status"></label>
<select id="edit_status" name="jobStatus" class="form-control"
data-size="10">
<option value=""></option>
<option value="NORMAL">NORMAL</option>
<option value="PAUSED">PAUSED</option>
</select>
</div>
<div class="input-group">
<span class="input-group-addon">job description</span>
<label for="edit_desc"></label>
<input type="text" alias="no-edit" name="desc" class="form-control" id="edit_desc"/>
</div>
</div>
Expand Down

0 comments on commit 79d0288

Please sign in to comment.