@SuppressWarnings("unchecked")
public static JobStatus scheduleJob(JobCurator jobCurator,
Scheduler scheduler, JobDetail detail,
Trigger trigger) throws SchedulerException {
JobStatus result = jobCurator.getByClassAndOwner(
detail.getJobDataMap().getString(JobStatus.TARGET_ID),
(Class<? extends KingpinJob>) detail.getJobClass());
if (result == null) {
return KingpinJob.scheduleJob(jobCurator, scheduler, detail, trigger);
}
if (result.getState() == JobStatus.JobState.PENDING ||
result.getState() == JobStatus.JobState.CREATED ||
result.getState() == JobStatus.JobState.WAITING) {
log.debug("Returning existing job id: " + result.getId());
return result;
}
log.debug("Scheduling job without a trigger: " + detail.getKey().getName());
JobStatus status = KingpinJob.scheduleJob(jobCurator, scheduler, detail, null);
return status;
}