}
if (log.isDebugEnabled()) {
log.debug("Deleting job {}", jobId);
}
JobEntity job = commandContext.getJobEntityManager().findJobById(jobId);
if (job == null) {
throw new ActivitiObjectNotFoundException("No job found with id '" + jobId + "'", Job.class);
}
// We need to check if the job was locked, ie acquired by the job acquisition thread
// This happens if the the job was already acquired, but not yet executed.
// In that case, we can't allow to delete the job.
if (job.getLockOwner() != null) {
throw new ActivitiException("Cannot delete job when the job is being executed. Try again later.");
}
return job;
}