use of org.quartz.JobExecutionException in project syncope by apache.
the class TaskJob method execute.
@Override
public void execute(final JobExecutionContext context) throws JobExecutionException {
try {
AuthContextUtils.execWithAuthContext(context.getMergedJobDataMap().getString(JobManager.DOMAIN_KEY), () -> {
try {
ImplementationDAO implementationDAO = ApplicationContextProvider.getApplicationContext().getBean(ImplementationDAO.class);
Implementation implementation = implementationDAO.find(context.getMergedJobDataMap().getString(DELEGATE_IMPLEMENTATION));
if (implementation == null) {
LOG.error("Could not find Implementation '{}', aborting", context.getMergedJobDataMap().getString(DELEGATE_IMPLEMENTATION));
} else {
delegate = ImplementationManager.<SchedTaskJobDelegate>build(implementation);
delegate.execute(taskKey, context.getMergedJobDataMap().getBoolean(DRY_RUN_JOBDETAIL_KEY), context);
}
} catch (Exception e) {
LOG.error("While executing task {}", taskKey, e);
throw new RuntimeException(e);
}
return null;
});
} catch (RuntimeException e) {
LOG.error("While executing task {}", taskKey, e);
throw new JobExecutionException("While executing task " + taskKey, e);
}
}
use of org.quartz.JobExecutionException in project openmeetings by apache.
the class EncodeJob method execute.
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
JobDataMap data = context.getJobDetail().getJobDataMap();
CaptureScreen capture = (CaptureScreen) data.get(CAPTURE_KEY);
if (screen == null) {
dim = capture.getDim();
screen = new Rectangle(dim.getSpinnerX(), dim.getSpinnerY(), dim.getSpinnerWidth(), dim.getSpinnerHeight());
}
long start = 0;
if (log.isTraceEnabled()) {
start = System.currentTimeMillis();
}
image = ScreenV1Encoder.getImage(dim, screen, robot);
if (log.isTraceEnabled()) {
log.trace(String.format("encode: Image was captured in %s ms, size %sk", System.currentTimeMillis() - start, 4 * image.length * image[0].length / 1024));
start = System.currentTimeMillis();
}
try {
VideoData vData = capture.getEncoder().encode(image);
if (log.isTraceEnabled()) {
long now = System.currentTimeMillis();
log.trace(String.format("encode: Image was encoded in %s ms, timestamp is %s", now - start, now - capture.getStartTime()));
}
capture.getFrames().offer(vData);
capture.getEncoder().createUnalteredFrame();
} catch (Exception e) {
log.error("Error while encoding: ", e);
}
}
use of org.quartz.JobExecutionException in project candlepin by candlepin.
the class PinsetterJobListenerDatabaseTest method verifyDatabaseConstraintIsNotViolated.
@Test
public void verifyDatabaseConstraintIsNotViolated() {
JobExecutionException e = mock(JobExecutionException.class);
String longstr = RandomStringUtils.randomAlphanumeric(300);
when(e.getMessage()).thenReturn(longstr);
JobDataMap map = new JobDataMap();
Principal principal = mock(Principal.class);
when(principal.getPrincipalName()).thenReturn("test-admin");
map.put(PinsetterJobListener.PRINCIPAL_KEY, principal);
map.put(JobStatus.TARGET_TYPE, JobStatus.TargetType.OWNER);
map.put(JobStatus.TARGET_ID, "10");
JobDetail detail = mock(JobDetail.class);
when(detail.getKey()).thenReturn(jobKey("name", "group"));
when(detail.getJobDataMap()).thenReturn(map);
JobStatus status = new JobStatus(detail);
// store a merge so we can find it in the test run
curator.merge(status);
JobExecutionContext ctx = mock(JobExecutionContext.class);
when(ctx.getMergedJobDataMap()).thenReturn(map);
when(ctx.getJobDetail()).thenReturn(detail);
// thing to be tested
listener.jobWasExecuted(ctx, e);
// verify the message stored is a substring of the long message
JobStatus verify = curator.find("name");
assertEquals(longstr.substring(0, JobStatus.RESULT_COL_LENGTH), verify.getResult());
}
use of org.quartz.JobExecutionException in project candlepin by candlepin.
the class PinsetterJobListenerTest method executedNullStatus.
@Test
public void executedNullStatus() {
JobExecutionException e = mock(JobExecutionException.class);
JobDetail detail = mock(JobDetail.class);
JobStatus status = mock(JobStatus.class);
when(detail.getKey()).thenReturn(jobKey("foo"));
when(ctx.getJobDetail()).thenReturn(detail);
when(jcurator.find(eq("foo"))).thenReturn(null);
listener.jobWasExecuted(ctx, e);
verifyZeroInteractions(status);
verify(jcurator, never()).merge(eq(status));
verifyZeroInteractions(e);
}
use of org.quartz.JobExecutionException in project candlepin by candlepin.
the class PinsetterJobListenerTest method handleResultTooLong.
@Test
public void handleResultTooLong() {
JobExecutionException e = mock(JobExecutionException.class);
JobDetail detail = mock(JobDetail.class);
JobDataMap map = new JobDataMap();
map.put(JobStatus.TARGET_TYPE, JobStatus.TargetType.OWNER);
when(detail.getKey()).thenReturn(jobKey("name", "group"));
when(detail.getJobDataMap()).thenReturn(map);
when(ctx.getJobDetail()).thenReturn(detail);
JobStatus status = new JobStatus(detail);
when(jcurator.find(eq("name"))).thenReturn(status);
String longstr = RandomStringUtils.randomAlphanumeric(300);
when(e.getMessage()).thenReturn(longstr);
listener.jobWasExecuted(ctx, e);
assertEquals(longstr.substring(0, JobStatus.RESULT_COL_LENGTH), status.getResult());
assertEquals(JobState.FAILED, status.getState());
verify(jcurator).merge(eq(status));
}
Aggregations