-
-
Save xerofun/ac8c19ef814253efedf5 to your computer and use it in GitHub Desktop.
Code to stop or abandon all jobs for a particular job name
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
@DELETE | |
@Produces(MediaType.APPLICATION_JSON) | |
@Path("active/jobs/{jobName}") | |
public Response stopJobExecutionsByName(@PathParam("jobName") String jobName) | |
{ | |
JobOperator jobOperator = BatchRuntime.getJobOperator(); | |
List<JobExecution> jobExecutions = new ArrayList<JobExecution>(); | |
for (Long executionId : jobOperator.getRunningExecutions(jobName)) | |
{ | |
JobExecution jobExecution = jobOperator.getJobExecution(executionId); | |
if (jobExecution.getBatchStatus() == BatchStatus.STOPPING | |
|| jobExecution.getBatchStatus() == BatchStatus.STOPPED) | |
{ | |
logger.info("Abandonning job execution {}, {}, {}, {}", | |
jobExecution.getExecutionId(), | |
jobExecution.getBatchStatus(), | |
jobExecution.getJobParameters(), | |
jobExecution.getExitStatus()); | |
jobOperator.abandon(executionId); | |
} | |
else | |
{ | |
logger.info("Stopping job execution {}, {}, {}, {}", | |
jobExecution.getExecutionId(), | |
jobExecution.getBatchStatus(), | |
jobExecution.getJobParameters(), | |
jobExecution.getExitStatus()); | |
jobOperator.stop(executionId); | |
} | |
jobExecutions.add(jobExecution); | |
} | |
return Response.ok(jobExecutions).build(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment