Cancel a running process instance but keep history of what it has done

Hi All,

I need to cancel ( may be abort is better word here) a running process and I do not need to do any compensation for it but I also want to keep the historical data of the process i.e. if it has already performed steps 1, 2 and 3 and while on 4th step it gets aborted/cancelled I need to have the historical data of what it has done.

the Delete API also deletes the history as I understand so that’s not useful here.

also I saw post Java API to cancel a process instance at any point without removing any history but it talks about suspending process that can be activated again, I do not need to activate it back.

any suggestions?

Thanks,
Vaibhav

You can delete a process instance without removing history using this delete call.

Hi Niall,

Thanks for the response.

In this post Does DELETE /history/process-instance/ Delete all Associated Data? I see the selected answer says that history will be deleted as well with the option you’ve mentioned so I’ve not tried that yet and looking for option which may be little explicit to not delete history, something like keepHistory = true on such endpoint.

Regards,
Vaibhav

The rest call in the post above isn’t actually the same rest call.
The one i’m suggesting works against the runtime database:

DELETE /process-instance/{id}

The one that’s mentioned in the above post is

DELETE /history/process-instance/{id}.

And this work runs against the histroy database.

ah right, my bad.

Thanks Niall, I’ve more follow up Q on the DELETE /process-instance/{id},

If it’s executing a step that has a REST call outside Camunda and before response comes back, we delete the process instance, what will happen to the thread waiting for the response? will there be any errors?

Also when I set skipSubprocesses=false, it is going to delete all the process hierarchy that this process created? e.g. P1 --> P2 --> P3 and I delete P1 with this option then P2 and P3 will also be deleted?

Regards,
Vaibhav

Only one tread can be active on any single process instance, so deleting the process wont interrupt any threads, it would have to wait for all threads to finish first.

Yes

if process has parallel paths then there are multiple tokens so multiple threads right, so multiple threads can be active on the process right? and if so, the delete api will wait for all of them to finish? of course if I’ve a timer or message receiving task waiting it would still kill it I assume?

Regards,
Vaibhav

Even when there are tokens created in parallel gateways, they are executed as they move through the model one at a time - in memory - when all tokens have moved the sate is commited to the database. So from the database’s perspective they’ve happened at the same time but while running only a single thread at a time moved a token.

The docs has this pretty good page about how transactions work, it’s worth reading for additional information.

ok, thanks Naill.