-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added REST API wrapper for inspecting and cancelling Batch2 jobs
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/main/java/ca/uhn/fhir/jpa/starter/controllers/JobController.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,48 @@ | ||
package ca.uhn.fhir.jpa.starter.controllers; | ||
|
||
|
||
import ca.uhn.fhir.batch2.api.IJobCoordinator; | ||
import ca.uhn.fhir.batch2.api.JobOperationResultJson; | ||
import ca.uhn.fhir.batch2.model.JobInstance; | ||
import ca.uhn.fhir.batch2.model.StatusEnum; | ||
import ca.uhn.fhir.batch2.models.JobInstanceFetchRequest; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.validation.constraints.Min; | ||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("control") | ||
public class JobController { | ||
|
||
public static final String JOBS = "jobs"; | ||
public static final String MY_CREATE_TIME = "myCreateTime"; | ||
private final IJobCoordinator theJobCoordinator; | ||
|
||
public JobController(IJobCoordinator theJobCoordinator) { | ||
this.theJobCoordinator = theJobCoordinator; | ||
} | ||
|
||
@RequestMapping(value = JOBS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) | ||
public List<JobInstance> getAllJobs( | ||
@RequestParam(name = "pageStart") @Min(0) Integer pageStart, | ||
@RequestParam(name = "batchSize") Integer batchSize, | ||
@RequestParam(name = "jobStatus", required = false) StatusEnum jobStatus) { | ||
|
||
var jobInstanceFetchRequest = new JobInstanceFetchRequest(); | ||
jobInstanceFetchRequest.setPageStart(pageStart); | ||
jobInstanceFetchRequest.setBatchSize(batchSize); | ||
if (jobStatus == null) jobInstanceFetchRequest.setJobStatus(""); | ||
else jobInstanceFetchRequest.setJobStatus(jobStatus.toString()); | ||
jobInstanceFetchRequest.setSort(Sort.by(Sort.Direction.DESC, MY_CREATE_TIME)); | ||
|
||
return theJobCoordinator.fetchAllJobInstances(jobInstanceFetchRequest).getContent(); | ||
} | ||
|
||
@RequestMapping(value = JOBS, method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) | ||
public JobOperationResultJson cancelInstance(@RequestParam(name = "instanceId") String instanceId) { | ||
return theJobCoordinator.cancelInstance(instanceId); | ||
} | ||
} |