Search in sources :

Example 1 with HistoricBatchEntity

use of org.camunda.bpm.engine.impl.batch.history.HistoricBatchEntity in project camunda-bpm-platform by camunda.

the class DefaultHistoryEventProducer method createBatchEvent.

protected HistoryEvent createBatchEvent(BatchEntity batch, HistoryEventTypes eventType) {
    HistoricBatchEntity event = new HistoricBatchEntity();
    event.setId(batch.getId());
    event.setType(batch.getType());
    event.setTotalJobs(batch.getTotalJobs());
    event.setBatchJobsPerSeed(batch.getBatchJobsPerSeed());
    event.setInvocationsPerBatchJob(batch.getInvocationsPerBatchJob());
    event.setSeedJobDefinitionId(batch.getSeedJobDefinitionId());
    event.setMonitorJobDefinitionId(batch.getMonitorJobDefinitionId());
    event.setBatchJobDefinitionId(batch.getBatchJobDefinitionId());
    event.setTenantId(batch.getTenantId());
    event.setEventType(eventType.getEventName());
    if (HistoryEventTypes.BATCH_START.equals(eventType)) {
        event.setStartTime(ClockUtil.getCurrentTime());
    }
    if (HistoryEventTypes.BATCH_END.equals(eventType)) {
        event.setEndTime(ClockUtil.getCurrentTime());
    }
    return event;
}
Also used : HistoricBatchEntity(org.camunda.bpm.engine.impl.batch.history.HistoricBatchEntity)

Example 2 with HistoricBatchEntity

use of org.camunda.bpm.engine.impl.batch.history.HistoricBatchEntity in project camunda-bpm-platform by camunda.

the class HistoricInstanceForCleanupQueryTest method testSortHistoricBatchesForCleanup.

@SuppressWarnings("unchecked")
@Test
public void testSortHistoricBatchesForCleanup() {
    Date startDate = ClockUtil.getCurrentTime();
    int daysInThePast = -11;
    ClockUtil.setCurrentTime(DateUtils.addDays(startDate, daysInThePast));
    // given
    List<Batch> list = Arrays.asList(helper.migrateProcessInstancesAsync(1), helper.migrateProcessInstancesAsync(1), helper.migrateProcessInstancesAsync(1));
    String batchType = list.get(0).getType();
    final Map<String, Integer> batchOperationsMap = new HashedMap();
    batchOperationsMap.put(batchType, 4);
    for (Batch batch : list) {
        helper.executeSeedJob(batch);
        helper.executeJobs(batch);
        ClockUtil.setCurrentTime(DateUtils.addDays(startDate, ++daysInThePast));
        helper.executeMonitorJob(batch);
    }
    ClockUtil.setCurrentTime(new Date());
    // when
    List<HistoricBatch> historicList = historyService.createHistoricBatchQuery().list();
    assertEquals(3, historicList.size());
    processEngineConfiguration.getCommandExecutorTxRequired().execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            HistoricBatchManager historicBatchManager = commandContext.getHistoricBatchManager();
            List<String> ids = historicBatchManager.findHistoricBatchIdsForCleanup(7, batchOperationsMap);
            assertEquals(3, ids.size());
            HistoricBatchEntity instance0 = historicBatchManager.findHistoricBatchById(ids.get(0));
            HistoricBatchEntity instance1 = historicBatchManager.findHistoricBatchById(ids.get(1));
            HistoricBatchEntity instance2 = historicBatchManager.findHistoricBatchById(ids.get(2));
            assertTrue(instance0.getEndTime().before(instance1.getEndTime()));
            assertTrue(instance1.getEndTime().before(instance2.getEndTime()));
            return null;
        }
    });
}
Also used : HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) Date(java.util.Date) HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) Batch(org.camunda.bpm.engine.batch.Batch) HistoricBatchEntity(org.camunda.bpm.engine.impl.batch.history.HistoricBatchEntity) List(java.util.List) HashedMap(org.apache.commons.collections.map.HashedMap) HistoricBatchManager(org.camunda.bpm.engine.impl.persistence.entity.HistoricBatchManager) Test(org.junit.Test)

Aggregations

HistoricBatchEntity (org.camunda.bpm.engine.impl.batch.history.HistoricBatchEntity)2 Date (java.util.Date)1 List (java.util.List)1 HashedMap (org.apache.commons.collections.map.HashedMap)1 Batch (org.camunda.bpm.engine.batch.Batch)1 HistoricBatch (org.camunda.bpm.engine.batch.history.HistoricBatch)1 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)1 HistoricBatchManager (org.camunda.bpm.engine.impl.persistence.entity.HistoricBatchManager)1 Test (org.junit.Test)1