Hi,I used RuntimeService.deleteProcessInstance to delete some old process instance by using the following code. The reason I add the processDefinition to the DeploymentCache is that they are some old definition and is not in the cache since the system has restarted many times.
if(pi.getEndTime()==null)
{
DeploymentCache dc =((ProcessEngineConfigurationImpl)processEngineConfiguration).getDeploymentManager().getProcessDefinitionCache();
ProcessDefinitionEntity pd =(ProcessDefinitionEntity)dc.get(pi.getProcessDefinitionId());
if(pd==null){
pd = (ProcessDefinitionEntity)repositoryService.createProcessDefinitionQuery().processDefinitionId(pi.getProcessDefinitionId()).singleResult();
dc.add(pi.getProcessDefinitionId(), pd);
this.runtimeService.deleteProcessInstance(processId,"user delete");
dc.remove(pi.getProcessDefinitionId());
}
else
this.runtimeService.deleteProcessInstance(processId,"user delete");
}
this.historyService.deleteHistoricProcessInstance(processId);
It throws a exception says that the process install is still running. After debugging, I found out that deleteProcessInstance method does not mark end of the historic process instance which means that the "endTime" field and "DELETE_REASON_" field in the database table "act_hi_procinst" is null after the method invoked.Therefore, I search the forum and found out this issue is fixed in ACT-1098. But it still doesn't work in my project. In my case, all the historic tasks are marked end with correct delete reason. But not the historic process instance.Thus, I went to detail of the implementation code in ExecutionEntity.java.
public void deleteCascade(String deleteReason) {
this.deleteReason = deleteReason;
this.deleteRoot = true;
performOperation(AtomicOperation.DELETE_CASCADE);
}
After reading I haven't found any place in ExecutionEntity.java does the "mark end " work.However, the HistoryManager.java, in the other hand, has the following code.
public void recordProcessInstanceEnd(String processInstanceId, String deleteReason, String activityId) {
if(isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
HistoricProcessInstanceEntity historicProcessInstance = getHistoricProcessInstanceManager()
.findHistoricProcessInstance(processInstanceId);
if (historicProcessInstance!=null) {
historicProcessInstance.markEnded(deleteReason);
historicProcessInstance.setEndActivityId(activityId);
}
}
}
And the method is called from ExecutionImpl.
org.activiti.engine.impl.history.HistoryManager.recordProcessInstanceEnd(String, String, String)
org.activiti.engine.impl.history.handler.ProcessInstanceEndHandler.notify(DelegateExecution)
org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(InterpretableExecution)
org.activiti.engine.impl.interceptor.CommandContext.performOperation(AtomicOperation, InterpretableExecution)
org.activiti.engine.impl.pvm.runtime.ExecutionImpl.performOperation(AtomicOperation)
So, what my code doesn't work. And I got confuse of ExecutionImpl with ExecutionEntity.Or is there any other method to delete a process instance completely.My version is from 5.8 at the begining and upgrade to 5.10 and to 5.12 now.