How to delete execution in camunda workflow

1,021 views
Skip to first unread message

jeff...@hermes-ottoint.com

unread,
Apr 13, 2015, 6:31:07 AM4/13/15
to camunda-...@googlegroups.com
What we want to do is to remove the created jobs when one event is triggered. We did this with:

wfManagementService.deleteJob(job.getId());

We found this can remove the jobs (Table: camunda.act_ru_job) successfully, but the related executions are still there in table camunda.act_ru_execution.

We tried to call remove() from ExecutionEntity:

Execution execution = wfRuntimeService.createExecutionQuery().executionId(executionId).singleResult();
((ExecutionEntity)execution).remove();

However, it will get NullPointerException on doing so.

java.lang.NullPointerException
at org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity.isExecutionTreePrefetchEnabled(ExecutionEntity.java:810)
at org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity.ensureParentInitialized(ExecutionEntity.java:1057)
at org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity.remove(ExecutionEntity.java:1154)

Does anyone know how to remove the runtime execution?

Thanks!

thorben....@camunda.com

unread,
Apr 13, 2015, 6:50:44 AM4/13/15
to camunda-...@googlegroups.com, jeff...@hermes-ottoint.com
Hi,

The short answer is: Don't do this and wait for CAM-3453 [1] being released with 7.3.0 or an upcoming alpha. With that feature, it will be possible to cancel activity/transition(i.e. async) instances via API.

The reasons are:
- even if you remove the execution successfully you very likely end up with an inconsistent execution tree and the engine won't be able to continue your process correctly
- deleting a single execution is not exposed via public API (for the above reason) and internal API is not stable

To answer the question on how to avoid the NPE:
You have to implement a custom command and execute your instructions in that. Then they are executed within one transaction. Internal API methods may assume they are executed from within a command. Cf. the service implementations and the commands they use for details.

Cheers,
Thorben

[1] https://app.camunda.com/jira/browse/CAM-3453

jeff...@hermes-ottoint.com

unread,
Apr 13, 2015, 7:13:31 AM4/13/15
to camunda-...@googlegroups.com, jeff...@hermes-ottoint.com
Dear Thorben,

Thanks for your quickly reply.
Based on your second suggestion, I can still remove the execution by using custom command.
However, according your first suggestion, you mean we'll gonna have problem even we remove the execution in that way.
So I'm a bit confuse that which way I should proceed.

Maybe there could be another way to model our process. Actually, the story is:

We have a task which has a due date, when the due date is reached, we'll send a reminder to an user. On the other hand, the due date can also be updated anytime by the user.

So what we model is one user task called 'Set due date' followed by a parallel gateway with 2 sequences.
One sequence goes to a timer job with the specified due date. (Timer job is followed by 'Send reminder' task)
Another sequence goes to a user task called 'Update due date'.

The 'update due date' task points back to 'set due date' task to form a loop.

So whenever the due date is updated, we'll need to cancel existing timer jobs (including the executions) and start new execution & timer job.
Otherwise, the activity instance count is not showing the correct number in Cockpit.
There could be more than one activity instances in the timer job.
But the correct number should be either 0 or 1.

Thanks!
Jeff


Thorben Lindhauer

unread,
Apr 13, 2015, 8:59:33 AM4/13/15
to camunda-...@googlegroups.com, jeff yung
Hi Jeff,

Regarding my first post, please stick to the "don't do it" answer :)
Otherwise, you are going to have a lot of trouble down the road since you really have to know engine internals when deleting/creating executions yourself.

On your use case:
What about instead of deleting and recreating the timer, you update the due date of the job?

That means, you add an execution listener [1] to the "end" event of the task in which you update the due date (assuming it is stored in a variable).
In that listener, you might execute the following:

Job timerJob = managementService.createJobQuery()
.processInstanceId(execution.getProcessInstanceId())
.activityId("timerActivity")
.singleResult();
// react appropriately if job has been executed meanwhile and is null

Date newDueDate = (Date) execution.getVariable("newDueDate");
managementService.setDueDate(timerJob.getId(), newDueDate);

Does that help?

Cheers,
Thorben

[1] http://docs.camunda.org/latest/guides/user-guide/#process-engine-delegation-code-execution-listener

----- Ursprüngliche Mail -----
Von: "jeff yung" <jeff...@hermes-ottoint.com>
An: camunda-...@googlegroups.com
CC: "jeff yung" <jeff...@hermes-ottoint.com>
Gesendet: Montag, 13. April 2015 13:13:31
Betreff: [camunda-bpm-users] Re: How to delete execution in camunda workflow
--
You received this message because you are subscribed to a topic in the Google Groups "camunda BPM users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/camunda-bpm-users/VqHuTo9I2L8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to camunda-bpm-us...@googlegroups.com.
To post to this group, send email to camunda-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/camunda-bpm-users/e4916322-c5d4-43c3-bddc-781574f4a15c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jeff...@hermes-ottoint.com

unread,
Apr 14, 2015, 3:26:39 AM4/14/15
to camunda-...@googlegroups.com, jeff...@hermes-ottoint.com
Hi Thorben,

We have considered your suggestion of updating the due date before.
It might not be the solution for our case because of some reasons.
Anyway, I appreciate for your help.
We'll also consider upgrade the camunda version to 7.3.

Thanks!
Jeff

Reply all
Reply to author
Forward
0 new messages