-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle db using liquibase and expose endpoints
- Loading branch information
1 parent
0ee9919
commit 93f39f2
Showing
7 changed files
with
114 additions
and
5 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
scheduler/boot-scheduler-quartz/src/main/java/com/scheduler/quartz/job/SampleJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...er/boot-scheduler-quartz/src/main/java/com/scheduler/quartz/model/response/JobStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.scheduler.quartz.model.response; | ||
|
||
public record JobStatus(String jobName, boolean completed) {} |
52 changes: 52 additions & 0 deletions
52
scheduler/boot-scheduler-quartz/src/main/java/com/scheduler/quartz/service/JobsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.scheduler.quartz.service; | ||
|
||
import com.scheduler.quartz.model.response.JobStatus; | ||
import java.util.Comparator; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import org.quartz.*; | ||
import org.quartz.impl.matchers.GroupMatcher; | ||
import org.quartz.utils.Key; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class JobsService { | ||
|
||
private final Scheduler scheduler; | ||
private final String groupName = "sample-group"; | ||
|
||
public JobsService(Scheduler scheduler) { | ||
this.scheduler = scheduler; | ||
} | ||
|
||
public boolean deleteJob(String id) throws SchedulerException { | ||
JobKey jobKey = new JobKey(id, groupName); | ||
return scheduler.deleteJob(jobKey); | ||
} | ||
|
||
public List<String> getJobs() throws SchedulerException { | ||
return scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName)).stream() | ||
.map(Key::getName) | ||
.sorted(Comparator.naturalOrder()) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public List<JobStatus> getJobsStatuses() throws SchedulerException { | ||
LinkedList<JobStatus> list = new LinkedList<>(); | ||
for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) { | ||
JobDetail jobDetail = scheduler.getJobDetail(jobKey); | ||
List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobDetail.getKey()); | ||
for (Trigger trigger : triggers) { | ||
Trigger.TriggerState triggerState = scheduler.getTriggerState(trigger.getKey()); | ||
if (Trigger.TriggerState.COMPLETE.equals(triggerState)) { | ||
list.add(new JobStatus(jobKey.getName(), true)); | ||
} else { | ||
list.add(new JobStatus(jobKey.getName(), false)); | ||
} | ||
} | ||
} | ||
list.sort(Comparator.comparing(JobStatus::jobName)); | ||
return list; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...ot-scheduler-quartz/src/main/java/com/scheduler/quartz/web/controller/JobsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.scheduler.quartz.web.controller; | ||
|
||
import com.scheduler.quartz.model.response.JobStatus; | ||
import com.scheduler.quartz.service.JobsService; | ||
import java.util.List; | ||
import org.quartz.SchedulerException; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/api/jobs") | ||
public class JobsController { | ||
|
||
private final JobsService jobsService; | ||
|
||
public JobsController(JobsService jobsService) { | ||
this.jobsService = jobsService; | ||
} | ||
|
||
@GetMapping | ||
List<String> getJobs() throws SchedulerException { | ||
return jobsService.getJobs(); | ||
} | ||
|
||
@GetMapping("/statuses") | ||
List<JobStatus> getJobsStatuses() throws SchedulerException { | ||
return jobsService.getJobsStatuses(); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
boolean deleteJob(@PathVariable String id) throws SchedulerException { | ||
return jobsService.deleteJob(id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters