use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class JobCuratorTest method getLatestByClassAndOwner.
@Test
public void getLatestByClassAndOwner() {
long offset = System.currentTimeMillis() - 7000;
newJobStatus(new Date(offset + 1000)).state(JobStatus.JobState.WAITING).owner("my_owner").jobClass(HealEntireOrgJob.class).create();
newJobStatus(new Date(offset + 2000)).state(JobStatus.JobState.RUNNING).owner("my_owner").jobClass(HealEntireOrgJob.class).create();
newJobStatus(new Date(offset + 3000)).state(JobStatus.JobState.RUNNING).owner("my_owner").jobClass(HealEntireOrgJob.class).create();
JobStatus expected = newJobStatus(new Date(offset + 4000)).state(JobStatus.JobState.CREATED).jobClass(HealEntireOrgJob.class).owner("my_owner").create();
// Would be chosen if the job class was correct
newJobStatus(new Date(offset + 5000)).state(JobStatus.JobState.WAITING).owner("my_owner").jobClass(RefreshPoolsJob.class).create();
// Would be chosen if the owner was correct
newJobStatus(new Date(offset + 6000)).state(JobStatus.JobState.WAITING).owner("some_owner").jobClass(HealEntireOrgJob.class).create();
// Would be chosen if the jobstate wasn't done
newJobStatus(new Date(offset + 7000)).state(JobStatus.JobState.FINISHED).jobClass(HealEntireOrgJob.class).owner("my_owner").create();
JobStatus result = curator.getByClassAndTarget("my_owner", HealEntireOrgJob.class);
assertEquals(expected, result);
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class JobCuratorTest method findWaitingJobsTest.
@Test
public void findWaitingJobsTest() {
JobStatus waitingJob1 = newJobStatus().state(JobStatus.JobState.WAITING).startTime(Util.yesterday()).create();
JobStatus waitingJob2 = newJobStatus().state(JobStatus.JobState.WAITING).startTime(Util.yesterday()).create();
JobStatus createdJob = newJobStatus().state(JobStatus.JobState.CREATED).startTime(Util.yesterday()).create();
JobStatus finishedJob = newJobStatus().state(JobStatus.JobState.FINISHED).startTime(Util.yesterday()).create();
List<JobStatus> waitingList = curator.findWaitingJobs().list();
assertTrue(waitingList.contains(waitingJob1));
assertTrue(waitingList.contains(waitingJob2));
assertFalse(waitingList.contains(createdJob));
assertFalse(waitingList.contains(finishedJob));
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class JobCuratorTest method findByPrincipalName.
@Test
public void findByPrincipalName() {
JobStatus job = newJobStatus().principalName("donald").owner("ducks").create();
List<JobStatus> jobs = this.curator.findByPrincipalName("donald").list();
assertNotNull(jobs);
assertEquals("donald", job.getPrincipalName());
assertEquals(job, jobs.get(0));
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class JobCuratorTest method updateWithLargeResult.
@Test
public void updateWithLargeResult() {
String longstr = RandomStringUtils.randomAlphanumeric(300);
JobExecutionContext ctx = mock(JobExecutionContext.class);
when(ctx.getFireTime()).thenReturn(new Date());
when(ctx.getJobRunTime()).thenReturn(1000L);
when(ctx.getResult()).thenReturn(longstr);
JobStatus status = newJobStatus().owner("terps").create();
status.update(ctx);
curator.merge(status);
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class PinsetterJobListener method updateJob.
@Transactional
private void updateJob(JobExecutionContext ctx, JobExecutionException exc) {
JobStatus status = curator.find(ctx.getJobDetail().getKey().getName());
if (status != null) {
if (exc != null) {
log.error("Job [" + status.getId() + "] failed.", exc);
status.setState(JobState.FAILED);
status.setResult(exc.getMessage());
if (exc.getCause() instanceof CandlepinException) {
status.setResultData(((CandlepinException) exc.getCause()).message());
}
} else {
status.update(ctx);
}
curator.merge(status);
} else {
log.debug("No jobinfo found for job: " + ctx);
}
}
Aggregations