public class SimpleJobService extends Object implements JobService, DisposableBean
JobService
that delegates most of its work to other
off-the-shelf components.Constructor and Description |
---|
SimpleJobService(SearchableJobInstanceDao jobInstanceDao,
SearchableJobExecutionDao jobExecutionDao,
SearchableStepExecutionDao stepExecutionDao,
org.springframework.batch.core.repository.JobRepository jobRepository,
org.springframework.batch.core.repository.dao.ExecutionContextDao executionContextDao,
javax.batch.operations.JobOperator jsrJobOperator,
AggregateJobQueryDao aggregateJobQueryDao,
org.springframework.cloud.dataflow.schema.SchemaVersionTarget schemaVersionTarget) |
Modifier and Type | Method and Description |
---|---|
org.springframework.batch.core.JobExecution |
abandon(Long jobExecutionId)
Mark the
JobExecution as ABANDONED. |
void |
addStepExecutions(org.springframework.batch.core.JobExecution jobExecution) |
int |
countJobExecutions()
Count the maximum number of executions that could be returned by
JobService.listJobExecutions(int, int) . |
int |
countJobExecutionsForJob(String name,
org.springframework.batch.core.BatchStatus status)
Count the job executions in the repository for a job.
|
int |
countJobInstances(String name)
Count the number of
job instances in the repository for a given job
name. |
int |
countJobs()
Count the total number of jobs that can be returned by
JobService.listJobs(int, int) . |
int |
countStepExecutionsForJobExecution(long jobExecutionId)
Count the step executions in the repository for a given job execution.
|
int |
countStepExecutionsForStep(String jobName,
String stepName)
Count the step executions in the repository for a given step name (or pattern).
|
void |
destroy()
Stop all the active jobs and wait for them (up to a time out) to finish processing.
|
org.springframework.batch.core.JobExecution |
getJobExecution(Long jobExecutionId)
Get a
JobExecution by id. |
Collection<org.springframework.batch.core.JobExecution> |
getJobExecutionsForJobInstance(String name,
Long jobInstanceId)
Get all the job executions for a given job instance.
|
org.springframework.batch.core.JobInstance |
getJobInstance(long jobInstanceId)
Get a
job instance by id. |
org.springframework.batch.core.JobParameters |
getLastJobParameters(String jobName)
Get the last
JobParameters used to execute a job successfully. |
org.springframework.batch.core.StepExecution |
getStepExecution(org.springframework.batch.core.JobExecution jobExecution,
Long stepExecutionId) |
org.springframework.batch.core.StepExecution |
getStepExecution(Long jobExecutionId,
Long stepExecutionId)
Locate a
StepExecution from its id and that of its parent JobExecution . |
Collection<org.springframework.batch.core.StepExecution> |
getStepExecutions(org.springframework.batch.core.JobExecution jobExecution) |
Collection<org.springframework.batch.core.StepExecution> |
getStepExecutions(Long jobExecutionId)
Get the
step executions for a given job execution (by id). |
Collection<String> |
getStepNamesForJob(String jobName)
Get the names of the steps in a job (or a historical list of recent execution names if
the Job is not launchable).
|
org.springframework.batch.core.JobExecution |
launch(String jobName,
org.springframework.batch.core.JobParameters jobParameters)
Launch a job with the parameters provided.
|
Collection<org.springframework.batch.core.JobExecution> |
listJobExecutions(int start,
int count)
List the
job executions in descending order of creation (usually
close to execution order). |
Collection<org.springframework.batch.core.JobExecution> |
listJobExecutionsForJob(String jobName,
org.springframework.batch.core.BatchStatus status,
int pageOffset,
int pageSize)
List the
job executions for a job in descending order of creation
(usually close to execution order). |
Collection<JobExecutionWithStepCount> |
listJobExecutionsForJobWithStepCount(Date fromDate,
Date toDate,
int start,
int count)
List the
job executions filtered by date range in
descending order of creation (usually close to execution order). |
Collection<JobExecutionWithStepCount> |
listJobExecutionsForJobWithStepCount(String jobName,
int start,
int count)
List the
job executions for a job in descending order
of creation (usually close to execution order). |
Collection<JobExecutionWithStepCount> |
listJobExecutionsForJobWithStepCountFilteredByJobInstanceId(int jobInstanceId,
int start,
int count)
List the
job executions filtered by job instance id in
descending order of creation (usually close to execution order). |
Collection<JobExecutionWithStepCount> |
listJobExecutionsForJobWithStepCountFilteredByTaskExecutionId(int taskExecutionId,
int start,
int count)
List the
job executions filtered by task execution id in
descending order of creation (usually close to execution order). |
Collection<JobExecutionWithStepCount> |
listJobExecutionsWithStepCount(int start,
int count)
List the
JobExecutions in descending order of
creation (usually close to execution order) without step execution data. |
Collection<org.springframework.batch.core.JobInstance> |
listJobInstances(String jobName,
int start,
int count)
List the
job instances in descending order of creation (usually
close to order of execution). |
Collection<String> |
listJobs(int start,
int count)
Query the job names in the system, either launchable or not.
|
Collection<org.springframework.batch.core.StepExecution> |
listStepExecutionsForStep(String jobName,
String stepName,
int start,
int count)
List the
step executions for a step in descending order of
creation (usually close to execution order). |
void |
removeInactiveExecutions()
Check all the active executions and see if they are still actually running.
|
org.springframework.batch.core.JobExecution |
restart(Long jobExecutionId)
Delegates launching to
restart(Long, org.springframework.batch.core.JobParameters) |
org.springframework.batch.core.JobExecution |
restart(Long jobExecutionId,
org.springframework.batch.core.JobParameters params)
Launch a job with the parameters provided.
|
void |
setShutdownTimeout(int shutdownTimeout)
Timeout for shutdown waiting for jobs to finish processing.
|
org.springframework.batch.core.JobExecution |
stop(Long jobExecutionId)
Send a signal to a job execution to stop processing.
|
int |
stopAll()
Send a stop signal to all running job executions.
|
public SimpleJobService(SearchableJobInstanceDao jobInstanceDao, SearchableJobExecutionDao jobExecutionDao, SearchableStepExecutionDao stepExecutionDao, org.springframework.batch.core.repository.JobRepository jobRepository, org.springframework.batch.core.repository.dao.ExecutionContextDao executionContextDao, javax.batch.operations.JobOperator jsrJobOperator, AggregateJobQueryDao aggregateJobQueryDao, org.springframework.cloud.dataflow.schema.SchemaVersionTarget schemaVersionTarget)
public void setShutdownTimeout(int shutdownTimeout)
shutdownTimeout
- in milliseconds (default 60 secs)public Collection<org.springframework.batch.core.StepExecution> getStepExecutions(Long jobExecutionId) throws org.springframework.batch.core.launch.NoSuchJobExecutionException
JobService
step executions
for a given job execution (by id).getStepExecutions
in interface JobService
jobExecutionId
- the parent job execution idorg.springframework.batch.core.launch.NoSuchJobExecutionException
- thrown if job execution specified does not existpublic Collection<org.springframework.batch.core.StepExecution> getStepExecutions(org.springframework.batch.core.JobExecution jobExecution)
getStepExecutions
in interface JobService
public void addStepExecutions(org.springframework.batch.core.JobExecution jobExecution)
addStepExecutions
in interface JobService
public org.springframework.batch.core.JobExecution restart(Long jobExecutionId) throws org.springframework.batch.core.launch.NoSuchJobException
restart(Long, org.springframework.batch.core.JobParameters)
restart
in interface JobService
jobExecutionId
- the job execution to restartJobExecution
associated with the restart.org.springframework.batch.core.launch.NoSuchJobException
- thrown if job does not existpublic org.springframework.batch.core.JobExecution restart(Long jobExecutionId, org.springframework.batch.core.JobParameters params) throws org.springframework.batch.core.launch.NoSuchJobException
JobService
restart
in interface JobService
jobExecutionId
- the job execution to restartparams
- the job parameters to use in the restartJobExecution
if successfulorg.springframework.batch.core.launch.NoSuchJobException
- thrown if job specified does not existpublic org.springframework.batch.core.JobExecution launch(String jobName, org.springframework.batch.core.JobParameters jobParameters) throws org.springframework.batch.core.launch.NoSuchJobException
JobService
launch
in interface JobService
jobName
- the job namejobParameters
- the JobParameters
JobExecution
if successfulorg.springframework.batch.core.launch.NoSuchJobException
- thrown if job specified does not existpublic org.springframework.batch.core.JobParameters getLastJobParameters(String jobName)
JobService
JobParameters
used to execute a job successfully.getLastJobParameters
in interface JobService
jobName
- the name of the jobpublic Collection<org.springframework.batch.core.JobExecution> listJobExecutions(int start, int count)
JobService
job executions
in descending order of creation (usually
close to execution order).listJobExecutions
in interface JobService
start
- the index of the first execution to returncount
- the maximum number of executionsJobExecution
public Collection<JobExecutionWithStepCount> listJobExecutionsWithStepCount(int start, int count)
JobService
JobExecutions
in descending order of
creation (usually close to execution order) without step execution data.listJobExecutionsWithStepCount
in interface JobService
start
- the index of the first execution to returncount
- the maximum number of executionsJobExecutionWithStepCount
public int countJobExecutions()
JobService
JobService.listJobExecutions(int, int)
.countJobExecutions
in interface JobService
public Collection<String> listJobs(int start, int count)
JobService
JobRepository
.listJobs
in interface JobService
start
- the start index of the job names to returncount
- the maximum number of job names to returnpublic int countJobs()
JobService
JobService.listJobs(int, int)
.countJobs
in interface JobService
public int stopAll()
JobService
stopAll
in interface JobService
public org.springframework.batch.core.JobExecution stop(Long jobExecutionId) throws org.springframework.batch.core.launch.NoSuchJobExecutionException, org.springframework.batch.core.launch.JobExecutionNotRunningException
JobService
Job
and Step
implementations to ensure that the signal is
obeyed. In particular, if users provide a custom Tasklet
to a Step
it
must check the signal in the JobExecution
itself.stop
in interface JobService
jobExecutionId
- the job execution id to stopJobExecution
that was stoppedorg.springframework.batch.core.launch.NoSuchJobExecutionException
- thrown if job execution specified does not existorg.springframework.batch.core.launch.JobExecutionNotRunningException
- thrown if the job execution specified is not
runningpublic org.springframework.batch.core.JobExecution abandon(Long jobExecutionId) throws org.springframework.batch.core.launch.NoSuchJobExecutionException, org.springframework.batch.core.repository.JobExecutionAlreadyRunningException
JobService
JobExecution
as ABANDONED. If a stop signal is ignored because the
process died this is the best way to mark a job as finished with (as opposed to
STOPPED). An abandoned job execution can be restarted, but a stopping one cannot.abandon
in interface JobService
jobExecutionId
- the job execution id to abortJobExecution
that was abortedorg.springframework.batch.core.launch.NoSuchJobExecutionException
- thrown if job execution specified does not existorg.springframework.batch.core.repository.JobExecutionAlreadyRunningException
- thrown if the job is running (it should be
stopped first)public int countJobExecutionsForJob(String name, org.springframework.batch.core.BatchStatus status) throws org.springframework.batch.core.launch.NoSuchJobException
JobService
countJobExecutionsForJob
in interface JobService
name
- the job namestatus
- the status of the joborg.springframework.batch.core.launch.NoSuchJobException
- thrown if job specified does not existpublic int countJobInstances(String name)
JobService
job instances
in the repository for a given job
name.countJobInstances
in interface JobService
name
- the name of the jobpublic org.springframework.batch.core.JobExecution getJobExecution(Long jobExecutionId) throws org.springframework.batch.core.launch.NoSuchJobExecutionException
JobService
JobExecution
by id.getJobExecution
in interface JobService
jobExecutionId
- the job execution idJobExecution
org.springframework.batch.core.launch.NoSuchJobExecutionException
- thrown if job execution specified does not existpublic Collection<org.springframework.batch.core.JobExecution> getJobExecutionsForJobInstance(String name, Long jobInstanceId) throws org.springframework.batch.core.launch.NoSuchJobException
JobService
getJobExecutionsForJobInstance
in interface JobService
name
- the name of the jobjobInstanceId
- the id of the job instanceorg.springframework.batch.core.launch.NoSuchJobException
- thrown if job specified does not existpublic org.springframework.batch.core.StepExecution getStepExecution(Long jobExecutionId, Long stepExecutionId) throws org.springframework.batch.core.launch.NoSuchJobExecutionException, NoSuchStepExecutionException
JobService
StepExecution
from its id and that of its parent JobExecution
.getStepExecution
in interface JobService
jobExecutionId
- the job execution idstepExecutionId
- the step execution idStepExecution
org.springframework.batch.core.launch.NoSuchJobExecutionException
- thrown if job execution specified does not existNoSuchStepExecutionException
- thrown if the step execution specified does not
existpublic org.springframework.batch.core.StepExecution getStepExecution(org.springframework.batch.core.JobExecution jobExecution, Long stepExecutionId) throws NoSuchStepExecutionException
getStepExecution
in interface JobService
NoSuchStepExecutionException
public Collection<JobExecutionWithStepCount> listJobExecutionsForJobWithStepCount(String jobName, int start, int count) throws org.springframework.batch.core.launch.NoSuchJobException
JobService
job executions
for a job in descending order
of creation (usually close to execution order).listJobExecutionsForJobWithStepCount
in interface JobService
jobName
- the job namestart
- the start index of the first job executioncount
- the maximum number of executions to returnJobExecutionWithStepCount
org.springframework.batch.core.launch.NoSuchJobException
- thrown if job specified does not existpublic Collection<org.springframework.batch.core.StepExecution> listStepExecutionsForStep(String jobName, String stepName, int start, int count) throws org.springframework.batch.core.step.NoSuchStepException
JobService
step executions
for a step in descending order of
creation (usually close to execution order).listStepExecutionsForStep
in interface JobService
jobName
- the name of the job associated with the step (or a pattern with
wildcards)stepName
- the step name (or a pattern with wildcards)start
- the start index of the first executioncount
- the maximum number of executions to returnStepExecution
org.springframework.batch.core.step.NoSuchStepException
- thrown if step specified does not existpublic int countStepExecutionsForStep(String jobName, String stepName) throws org.springframework.batch.core.step.NoSuchStepException
JobService
countStepExecutionsForStep
in interface JobService
jobName
- the job name (or a pattern with wildcards)stepName
- the step name (or a pattern with wildcards)org.springframework.batch.core.step.NoSuchStepException
- thrown if step specified does not existpublic int countStepExecutionsForJobExecution(long jobExecutionId)
JobService
countStepExecutionsForJobExecution
in interface JobService
jobExecutionId
- the id of the job execution.public org.springframework.batch.core.JobInstance getJobInstance(long jobInstanceId) throws org.springframework.batch.core.launch.NoSuchJobInstanceException
JobService
job instance
by id.getJobInstance
in interface JobService
jobInstanceId
- the id of the instancejob instance
org.springframework.batch.core.launch.NoSuchJobInstanceException
- thrown if the job instance specified does not existpublic Collection<org.springframework.batch.core.JobInstance> listJobInstances(String jobName, int start, int count) throws org.springframework.batch.core.launch.NoSuchJobException
JobService
job instances
in descending order of creation (usually
close to order of execution).listJobInstances
in interface JobService
jobName
- the name of the jobstart
- the index of the first to returncount
- the maximum number of instances to returnjob instances
org.springframework.batch.core.launch.NoSuchJobException
- thrown if job specified does not existpublic Collection<String> getStepNamesForJob(String jobName) throws org.springframework.batch.core.launch.NoSuchJobException
JobService
getStepNamesForJob
in interface JobService
jobName
- the name of the jobCollection
of step names.org.springframework.batch.core.launch.NoSuchJobException
- thrown if the job name cannot be locatedpublic Collection<org.springframework.batch.core.JobExecution> listJobExecutionsForJob(String jobName, org.springframework.batch.core.BatchStatus status, int pageOffset, int pageSize)
JobService
job executions
for a job in descending order of creation
(usually close to execution order).listJobExecutionsForJob
in interface JobService
jobName
- the job namestatus
- the status of the job executionpageOffset
- the start index of the first job executionpageSize
- the maximum number of executions to returnJobExecution
public Collection<JobExecutionWithStepCount> listJobExecutionsForJobWithStepCount(Date fromDate, Date toDate, int start, int count)
JobService
job executions
filtered by date range in
descending order of creation (usually close to execution order).listJobExecutionsForJobWithStepCount
in interface JobService
fromDate
- the date which start date must be greater than.toDate
- the date which start date must be less than.start
- the start index of the first job executioncount
- the maximum number of executions to returnJobExecutionWithStepCount
public Collection<JobExecutionWithStepCount> listJobExecutionsForJobWithStepCountFilteredByJobInstanceId(int jobInstanceId, int start, int count)
JobService
job executions
filtered by job instance id in
descending order of creation (usually close to execution order).listJobExecutionsForJobWithStepCountFilteredByJobInstanceId
in interface JobService
jobInstanceId
- the job instance id associated with the execution.start
- the start index of the first job executioncount
- the maximum number of executions to returnJobExecutionWithStepCount
public Collection<JobExecutionWithStepCount> listJobExecutionsForJobWithStepCountFilteredByTaskExecutionId(int taskExecutionId, int start, int count)
JobService
job executions
filtered by task execution id in
descending order of creation (usually close to execution order).listJobExecutionsForJobWithStepCountFilteredByTaskExecutionId
in interface JobService
taskExecutionId
- the task execution id associated with the execution.start
- the start index of the first job executioncount
- the maximum number of executions to returnJobExecutionWithStepCount
public void destroy() throws Exception
destroy
in interface DisposableBean
Exception
@Scheduled(fixedDelay=60000L) public void removeInactiveExecutions()
Copyright © 2024 Pivotal Software, Inc.. All rights reserved.