use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class PinsetterKernel method scheduleJob.
private JobStatus scheduleJob(JobDetail detail, String grpName, Trigger trigger) throws PinsetterException {
JobDetailImpl detailImpl = (JobDetailImpl) detail;
detailImpl.setGroup(grpName);
try {
JobStatus status = (JobStatus) (detail.getJobClass().getMethod("scheduleJob", JobCurator.class, Scheduler.class, JobDetail.class, Trigger.class).invoke(null, jobCurator, scheduler, detail, trigger));
if (log.isDebugEnabled()) {
log.debug("Scheduled " + detailImpl.getFullName());
}
return status;
} catch (Exception e) {
log.error("There was a problem scheduling " + detail.getKey().getName(), e);
throw new PinsetterException("There was a problem scheduling " + detail.getKey().getName(), e);
}
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class PinsetterTriggerListener method triggerMisfired.
@Override
public void triggerMisfired(Trigger trigger) {
log.warn("Trigger misfired for for Job: \nKey: {}\nJob Key: {}\nStart: {}\nEnd: {}\n" + "Final Fire Time: {}\nNext Fire Time: {}\nMisfire Instruction: {}\nPriority: {}", trigger.getKey(), trigger.getJobKey(), trigger.getStartTime(), trigger.getEndTime(), trigger.getFinalFireTime(), trigger.getNextFireTime(), trigger.getMisfireInstruction(), trigger.getPriority());
try {
String id = trigger.getJobKey().getName();
JobStatus js = jobCurator.find(id);
if (js == null) {
throw new RuntimeException("No JobStatus for job with id of " + id);
}
// if may not refire again, change to fail
if (!trigger.mayFireAgain()) {
log.warn("Job {} not allowed to fire again. Setting state to FAILED.", id);
js.setState(JobStatus.JobState.FAILED);
js.setResult("Failed run. Will not attempt again.");
} else {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
js.setResult("Will reattempt job at or after " + sdf.format(trigger.getNextFireTime()));
js.setState(JobStatus.JobState.PENDING);
}
jobCurator.merge(js);
} catch (Exception e) {
log.error("Unable to capture misfire into job status: {}", e.getMessage());
}
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class UniqueByEntityJob method scheduleJob.
@SuppressWarnings("unchecked")
public static JobStatus scheduleJob(JobCurator jobCurator, Scheduler scheduler, JobDetail detail, Trigger trigger) throws SchedulerException {
JobStatus result = jobCurator.getByClassAndTarget(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;
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class JobResourceTest method getStatusAndDeleteIfFinishedTest.
@Test
public void getStatusAndDeleteIfFinishedTest() {
// nothing to delete..
when(jobCurator.find("bogus_id")).thenReturn(new JobStatus());
jobResource.getStatusAndDeleteIfFinished("foobar");
verify(jobCurator, never()).delete(any(JobStatus.class));
// now lets make a deletable JobStatus
JobStatus finishedJobStatus = new JobStatus();
finishedJobStatus.setState(JobState.FINISHED);
when(jobCurator.find("deletable_id")).thenReturn(finishedJobStatus);
jobResource.getStatusAndDeleteIfFinished("deletable_id");
verify(jobCurator, atLeastOnce()).delete(finishedJobStatus);
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class JobResourceTest method getStatusesByPrincipal.
@Test
public void getStatusesByPrincipal() {
List<JobStatus> statuses = new ArrayList<>();
JobStatus status = new JobStatus();
statuses.add(status);
CandlepinQuery query = mock(CandlepinQuery.class);
when(query.list()).thenReturn(statuses);
when(query.iterate()).thenReturn(new MockResultIterator(statuses.iterator()));
when(query.iterate(anyInt(), anyBoolean())).thenReturn(new MockResultIterator(statuses.iterator()));
when(jobCurator.findByPrincipalName(eq("admin"))).thenReturn(query);
this.mockCPQueryTransform(query);
Collection<JobStatusDTO> real = jobResource.getStatuses(null, null, "admin").list();
assertNotNull(real);
assertEquals(1, real.size());
}
Aggregations