Skip to content

Instantly share code, notes, and snippets.

@xerofun
Created September 10, 2015 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xerofun/ac8c19ef814253efedf5 to your computer and use it in GitHub Desktop.
Save xerofun/ac8c19ef814253efedf5 to your computer and use it in GitHub Desktop.
Code to stop or abandon all jobs for a particular job name
@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