Skip to content

Commit

Permalink
Renamed Status enum for WS response, disallow triggering disabled jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwilshire committed Oct 30, 2024
1 parent 896af9e commit 74199f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public class ScheduledJobWS {
@Autowired ScheduledJobManager scheduledJobManager;

private final ResponseEntity<ScheduledJobResponse> notFoundResponse =
createResponse(HttpStatus.NOT_FOUND, ScheduledJobResponse.Status.ERROR, "Job doesn't exist");
createResponse(
HttpStatus.NOT_FOUND, ScheduledJobResponse.Status.FAILURE, "Job doesn't exist");

@RequestMapping(method = RequestMethod.GET, value = "/api/jobs")
@ResponseStatus(HttpStatus.OK)
Expand All @@ -61,7 +62,7 @@ public ScheduledJobDTO getJob(@PathVariable UUID id) {
new ResponseStatusException(HttpStatus.NOT_FOUND, "Job not found with id: " + id));
}

@RequestMapping(method = RequestMethod.POST, value = "/api/jobs/{id}/trigger")
@RequestMapping(method = RequestMethod.POST, value = "/api/jobs/{id}")
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<ScheduledJobResponse> triggerJob(@PathVariable UUID id) {

Expand All @@ -72,6 +73,12 @@ public ResponseEntity<ScheduledJobResponse> triggerJob(@PathVariable UUID id) {
ScheduledJob scheduledJob = optScheduledJob.get();
JobKey jobKey = scheduledJobManager.getJobKey(scheduledJob);

if (!scheduledJob.getEnabled())
return createResponse(
HttpStatus.CONFLICT,
ScheduledJobResponse.Status.FAILURE,
"Job is disabled, trigger request ignored");

try {
if (!scheduledJobManager.getScheduler().checkExists(jobKey)) return notFoundResponse;

Expand All @@ -81,7 +88,7 @@ public ResponseEntity<ScheduledJobResponse> triggerJob(@PathVariable UUID id) {
if (jobExecutionContext.getJobDetail().getKey().equals(jobKey)) {
return createResponse(
HttpStatus.CONFLICT,
ScheduledJobResponse.Status.ERROR,
ScheduledJobResponse.Status.FAILURE,
"Job is currently running, trigger request ignored");
}
}
Expand All @@ -97,7 +104,7 @@ public ResponseEntity<ScheduledJobResponse> triggerJob(@PathVariable UUID id) {
logger.error(
"Error triggering job manually, job: {}", jobKey.getName() + ":" + jobKey.getGroup(), e);
return createResponse(
HttpStatus.INTERNAL_SERVER_ERROR, ScheduledJobResponse.Status.ERROR, e.getMessage());
HttpStatus.INTERNAL_SERVER_ERROR, ScheduledJobResponse.Status.FAILURE, e.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public ScheduledJobResponse(Status status, String message) {
}

public enum Status {
ERROR,
FAILURE,
SUCCESS;

@JsonValue
Expand Down

0 comments on commit 74199f6

Please sign in to comment.