cancel
Showing results for 
Search instead for 
Did you mean: 

deleteProcessInstance() - Are there any task events fired?

cold_gin
Champ in-the-making
Champ in-the-making
Hi. I have two ExecutionListeners, one for process events and one for task events. When I call

deleteProcessInstance(processInstanceId, deleteReason);

the process event listener receives an end event but I do not receive task completed (or cancelled) events in the task listener for the active tasks. Why is that? When I check the DB before and after process deletion I see the process instance and task records get deleted (which is fine), but I wanted to execute some logic in my task event listener for the completed (or cancelled) tasks.

I am currently listening for start/end events on both listeners via the XML configuration. Is there another event type that I can add in order to detect cancellation or completion of the currently active tasks when deleteProcessInstance() is called?

Thanks in advance.
7 REPLIES 7

cold_gin
Champ in-the-making
Champ in-the-making
One clarification - my listeners are configured as spring beans, so when I say "listening for start / end events on both listeners via XML", I am referring to configuring the spring beans to listen for start / end events on the process listener, and I am configuring the task listener bean to listen for "all" events. I am not configuring the listeners in any way inside of the workflow definitions.

Thanks

cold_gin
Champ in-the-making
Champ in-the-making
Well I found this test case on github which seems to indicate that an ENTITY_DELETED event is raised by deleteProcessInstance() for the tasks (???). Should I listen for these deletion events in my task ActivityListener, or perhaps a separate ActivityListener?:

<code>
public void testDeleteEventDoesNotDispathComplete() {

// Delete process, should delete task as well, but not complete
runtimeService.deleteProcessInstance(processInstance.getId(), "testing task delete events");
               
assertEquals(1, listener.getEventsReceived().size());
ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
assertTrue(event.getEntity() instanceof Task);
Task taskFromEvent = (Task) event.getEntity();
assertEquals(task.getId(), taskFromEvent.getId());

}
</code>

Unit test is here in github:

https://github.com/Activiti/Activiti/blob/master/modules/activiti-engine/src/test/java/org/activiti/...

Thanks

frederikherema1
Star Contributor
Star Contributor
That functionality (engine-wide event-dispatching) has been added in 5.15. These events are NOT execution-listeners and NOT task-listeners. This fires low-level events, like deleting entities. When a process-instance is deleted, the tasks are first deleted…

Thanks for your response Frederik. I have been tracking the RuntimeService deleteProcessInstance() code through github. I see that eventually org.activiti.engine.impl.persistence.entity.TaskEntityManager deleteTasksByProcessInstanceId() gets called (after the commandExecutor calls execute() on DeleteProcessInstanceCmd), and TaskListener.EVENTNAME_DELETE deletion events are eventually fired via the org.activiti.engine.impl.persistence.entity.TaskEntity class, and that deletion event has a listener created for it by the org.activiti.engine.impl.task.TaskDefinition class, *after* this fix from Nov. 25, 2013 was applied:

https://github.com/Activiti/Activiti/pull/178
https://github.com/Activiti/Activiti/commit/39c99c5a4ce6e5344387c78e16d4772fc7a3e5c3

Now, I do not currently have this code in my 5.13 version of Activiti in the org.activiti.engine.impl.task.TaskDefinition class.

I believe that you are saying that these org.activiti.engine.delegate.TaskListener events (ie - EVENTNAME_DELETE) would *not* be detected when I have a Spring tasklistener bean configured (my listener bean type is org.activiti.bpmn.model.ActivitiListener, with event property argument = "all", and it currently receives task start and end events during process execution). Is that correct? If not, would an upgrade to Activiti version 5.14 allow task deletion events to be detected by my Spring taskListener bean? As I said, I do receive an "end" event in my process listener bean when deleteProcessInstance() is called.

Thanks in advance for any further clarification that you can offer.

cold_gin
Champ in-the-making
Champ in-the-making
Ah ha! Wait a minute, this is exactly the issue that i am describing:

http://jira.codehaus.org/browse/ACT-1560

and I believe it is resolved through ACT-1859 according to the last post on the ticket, which I believe means that an upgrade to 5.14 should resolve it in my case???

Please see this post also, where my exact issue is described, and where I found the reference to ACT-1560:

http://forums.activiti.org/content/tasklistener-deleted-tasks

cold_gin
Champ in-the-making
Champ in-the-making
Hmmm.. I downloaded the source code for Activiti 5.14. The fix version on the ACT-1859 ticket does say version 5.15, and I don't see the modification that adds the listener for the task deletion event inside of the org.activiti.engine.impl.task.TaskDefinition class inside of the 5.14 code. So I guess that is why you are saying I would need version 5.15?

frederikherema1
Star Contributor
Star Contributor
Yes, 5.15 is the version you need…