Search in sources :

Example 21 with JobExecutionEvent

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"));
}
Also used : JobExecutionEvent(com.dangdang.ddframe.job.event.type.JobExecutionEvent) Test(org.junit.Test)

Example 22 with JobExecutionEvent

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();
    }
}
Also used : JobExecutionEvent(com.dangdang.ddframe.job.event.type.JobExecutionEvent) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 23 with JobExecutionEvent

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);
        }
    }
}
Also used : JobExecutionEvent(com.dangdang.ddframe.job.event.type.JobExecutionEvent) ShardingContext(com.dangdang.ddframe.job.api.ShardingContext)

Example 24 with JobExecutionEvent

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));
}
Also used : Condition(com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch.Condition) JobExecutionEvent(com.dangdang.ddframe.job.event.type.JobExecutionEvent) Test(org.junit.Test)

Aggregations

JobExecutionEvent (com.dangdang.ddframe.job.event.type.JobExecutionEvent)24 Test (org.junit.Test)20 Condition (com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch.Condition)8 Date (java.util.Date)2 HashMap (java.util.HashMap)2 ShardingContext (com.dangdang.ddframe.job.api.ShardingContext)1 TestJobEventConfiguration (com.dangdang.ddframe.job.event.fixture.TestJobEventConfiguration)1 JobExecutionEventThrowable (com.dangdang.ddframe.job.event.type.JobExecutionEventThrowable)1 JobStatusTraceEvent (com.dangdang.ddframe.job.event.type.JobStatusTraceEvent)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 LinkedList (java.util.LinkedList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1