cancel
Showing results for 
Search instead for 
Did you mean: 

Foolproof Way to Delete all Process Instance Data

mrbahr2003
Champ in-the-making
Champ in-the-making
Hi,

All of my Activiti processes are atomic (no wait states).  We use activiti to coordinate complex computer workflows.  There is no human interaction.  Therefore, at the end of a process, we want to delete all traces of the process instance and it's historical data to keep the in-memory H2 data store clean so we don't run out of memory.  Here is what we have:


            ProcessInstance inst = null;
         try {
            inst = runtimeService
                  .startProcessInstanceByKey("domyprocess",
                        variables);

            List<HistoricVariableInstance> hvi = historyService
                  .createHistoricVariableInstanceQuery()
                  .processInstanceId(inst.getProcessInstanceId()).list();

                for (HistoricVariableInstance uu : hvi) {
               String xx = uu.getVariableName();
               Object yy = uu.getValue();
               variables.put(uu.getVariableName(), uu.getValue());
            }
         } catch (Exception e) {
            e.printStackTrace();
         }
            finally {
                if (inst != null) {
                    try {
                        runtimeService.deleteProcessInstance(inst.getProcessInstanceId(), "Process End");
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    try {
                        historyService.deleteHistoricProcessInstance(inst.getProcessInstanceId());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }


I am assuming that if the process ends correctly (reaching the end task), the process instance is automatically deleted.  I surmised this because if I try to delete the process instance after completion, it throws the following:

 
org.activiti.engine.ActivitiObjectNotFoundException: No process instance found for id '11'
   at org.activiti.engine.impl.persistence.entity.ExecutionEntityManager.deleteProcessInstance(ExecutionEntityManager.java:61)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntityManager.deleteProcessInstance(ExecutionEntityManager.java:54)
   at org.activiti.engine.impl.cmd.DeleteProcessInstanceCmd.execute(DeleteProcessInstanceCmd.java:41)
   at org.activiti.engine.impl.cmd.DeleteProcessInstanceCmd.execute(DeleteProcessInstanceCmd.java:25)
   at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:61)
   at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:42)
   at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
   at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:40)
   at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:37)
   at org.activiti.engine.impl.RuntimeServiceImpl.deleteProcessInstance(RuntimeServiceImpl.java:86)
   at com.presidioHealth.ppsCodingLibrary.transition.service.TransitionBillingCodesService.transitionBillingCodes(TransitionBillingCodesService.java:128)
   at com.presidioHealth.ppsCodingLibrary.billingcodes.BillingCodesService.getLockForCoding(BillingCodesService.java:199)
   at com.presidioHealth.ppsCodingLibrary.codingStatus.TestGetLockForCoding.testGetLock(TestGetLockForCoding.java:33)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:606)
   at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
   at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
   at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
   at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
   at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
   at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
   at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
   at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:233)
   at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87)
   at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
   at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
   at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
   at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
   at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
   at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
   at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
   at org.junit.runners.ParentRunner.run(ParentRunner.java:292)


Then, I delete the process instance from history.

Is there anything else I need to do to keep the database clean?

Thanks,
Tom

3 REPLIES 3

mikedias
Champ in-the-making
Champ in-the-making
Hi,

You can disable the process engine history in the process engine configuration.

mrbahr2003
Champ in-the-making
Champ in-the-making
Am I to assume that if the process completes, other than history (which we can turn off), there is nothing else persisted in the database with regard to the process instance.  Is that correct?

Thanks,
Tom

trademak
Star Contributor
Star Contributor
Hi Tom,

If you turn off history, and a process instance is completed, no information will be persisted in the database about this process instance.

Best regards,