use of com.dangdang.ddframe.job.event.type.JobExecutionEvent in project elastic-job by dangdangdotcom.
the class JobEventRdbStorageTest method assertUpdateJobExecutionEventWhenFailureAndMessageExceed.
@Test
public void assertUpdateJobExecutionEventWhenFailureAndMessageExceed() throws SQLException {
JobExecutionEvent startEvent = new JobExecutionEvent("fake_task_id", "test_job", ExecutionSource.NORMAL_TRIGGER, 0);
assertTrue(storage.addJobExecutionEvent(startEvent));
StringBuilder failureMsg = new StringBuilder();
for (int i = 0; i < 600; i++) {
failureMsg.append(i);
}
JobExecutionEvent failEvent = startEvent.executionFailure(new RuntimeException("failure" + failureMsg.toString()));
assertTrue(storage.addJobExecutionEvent(failEvent));
assertThat(failEvent.getFailureCause(), startsWith("java.lang.RuntimeException: failure"));
}
use of com.dangdang.ddframe.job.event.type.JobExecutionEvent in project elastic-job by dangdangdotcom.
the class AbstractElasticJobExecutor method process.
private void process(final ShardingContexts shardingContexts, final JobExecutionEvent.ExecutionSource executionSource) {
Collection<Integer> items = shardingContexts.getShardingItemParameters().keySet();
if (1 == items.size()) {
int item = shardingContexts.getShardingItemParameters().keySet().iterator().next();
JobExecutionEvent jobExecutionEvent = new JobExecutionEvent(shardingContexts.getTaskId(), jobName, executionSource, item);
process(shardingContexts, item, jobExecutionEvent);
return;
}
final CountDownLatch latch = new CountDownLatch(items.size());
for (final int each : items) {
final JobExecutionEvent jobExecutionEvent = new JobExecutionEvent(shardingContexts.getTaskId(), jobName, executionSource, each);
if (executorService.isShutdown()) {
return;
}
executorService.submit(new Runnable() {
@Override
public void run() {
try {
process(shardingContexts, each, jobExecutionEvent);
} finally {
latch.countDown();
}
}
});
}
try {
latch.await();
} catch (final InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
use of com.dangdang.ddframe.job.event.type.JobExecutionEvent in project elastic-job by dangdangdotcom.
the class AbstractElasticJobExecutor method process.
private void process(final ShardingContexts shardingContexts, final int item, final JobExecutionEvent startEvent) {
if (shardingContexts.isAllowSendJobEvent()) {
jobFacade.postJobExecutionEvent(startEvent);
}
log.trace("Job '{}' executing, item is: '{}'.", jobName, item);
JobExecutionEvent completeEvent = null;
try {
process(new ShardingContext(shardingContexts, item));
completeEvent = startEvent.executionSuccess();
log.trace("Job '{}' executed, item is: '{}'.", jobName, item);
// CHECKSTYLE:OFF
} catch (final Throwable cause) {
// CHECKSTYLE:ON
completeEvent = startEvent.executionFailure(cause);
itemErrorMessages.put(item, ExceptionUtil.transform(cause));
jobExceptionHandler.handleException(jobName, cause);
} finally {
if (shardingContexts.isAllowSendJobEvent()) {
jobFacade.postJobExecutionEvent(completeEvent);
}
}
}
use of com.dangdang.ddframe.job.event.type.JobExecutionEvent in project elastic-job by dangdangdotcom.
the class CloudJobRestfulApiTest method assertFindJobExecutionEvents.
@Test
public void assertFindJobExecutionEvents() throws Exception {
ReflectionUtils.setFieldValue(CloudJobRestfulApi.class, CloudJobRestfulApi.class.getDeclaredField("jobEventRdbSearch"), getJobEventRdbSearch());
JobExecutionEvent jobExecutionEvent = new JobExecutionEvent("fake_task_id", "test_job", JobExecutionEvent.ExecutionSource.NORMAL_TRIGGER, 0);
when(getJobEventRdbSearch().findJobExecutionEvents(any(Condition.class))).thenReturn(new Result<>(0, Lists.newArrayList(jobExecutionEvent)));
assertThat(sentGetRequest("http://127.0.0.1:19000/job/events/executions?" + buildFindJobEventsQueryParameter()), is(GsonFactory.getGson().toJson(new Result<>(0, Lists.newArrayList(jobExecutionEvent)))));
verify(getJobEventRdbSearch()).findJobExecutionEvents(any(Condition.class));
}
Aggregations