int historyLevel = configuration.getHistoryLevel();
if(historyLevel>=ProcessEngineConfigurationImpl.HISTORYLEVEL_AUDIT) {
final HistoryEventProducer eventProducer = configuration.getHistoryEventProducer();
final HistoryEventHandler eventHandler = configuration.getHistoryEventHandler();
TaskEntity taskEntity = Context.getCommandContext()
.getDbEntityManager()
.selectById(TaskEntity.class, taskId);
HistoryEvent evt = eventProducer.createTaskInstanceCompleteEvt(taskEntity, deleteReason);
eventHandler.handleEvent(evt);
}
}